【问题标题】:XSLT, Add an attribute to the root node of the resultant xml fileXSLT,将属性添加到生成的 xml 文件的根节点
【发布时间】:2011-09-04 06:19:39
【问题描述】:

我正在使用 xslt 将两个 xml 文件添加在一起,然后这个生成的 xml 文件应该符合模式。我可以将两个 xml 文件添加在一起,但结果应该在根元素中具有 noNamespaceSchemaLocation="file:///osba.xsd" 作为属性。

这是我的 .xsl 文件:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1" indent="yes" />
<xsl:variable name="with" select="'reception.xml'" />

<xsl:template match="@*|node()" >
  <xsl:copy>
    <xsl:apply-templates select="@*|node()" />
  </xsl:copy>
</xsl:template>

<xsl:template match="bd">
 <xsl:copy>
  <xsl:apply-templates select="@*|node()" />
  <xsl:variable name="info" select="document($with)/reception/bd[title=current()/title]/." />
  <xsl:for-each select="$info/*">
    <xsl:if test="name()!='title'">
      <xsl:copy-of select="." />
    </xsl:if>
  </xsl:for-each>
 </xsl:copy>
</xsl:template>
</xsl:transform>

我想添加如下内容:

<xsl:template match="/*" >
  <xsl:attribute name="noNamespaceSchemaLocation"><![CDATA[file:///I:/IMY%20Project/XML%20Files/osba.xsd]]></xsl:attribute>
<xsl:apply-templates/>                          

如果当前元素是 root,我还没有找到任何匹配的方法,我也在考虑可能在第一个 xsl:template 中放置一个 xsl:if test="root" 类型的交易。

感谢您的帮助

【问题讨论】:

    标签: xml xslt xslt-1.0


    【解决方案1】:

    类似这样的:

     

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-25
      • 1970-01-01
      • 2012-09-25
      • 2012-07-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-24
      相关资源
      最近更新 更多