2010-05-04 47 views
0

我正在第一次使用xslt,我真的不明白为什么这个xsl不会复制源xml中的属性。也许有人可以给我一个提示?为什么不从源XML文件复制这个dokument属性?

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output omit-xml-declaration="yes" indent="yes"/> 
    <xsl:variable name="rpl" select="document('ParamInvoice.xml')"/> 
    <xsl:template match="/"> 
     <xsl:copy> 
     <xsl:apply-templates select="* | @*"/> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template match="*"> 
     <xsl:variable name="vInvoiceElement" select="$rpl/StoraInvoice/*[name()=name(current())]"/> 
     <xsl:copy> 
     <xsl:if test="$vInvoiceElement/Attribute"> 
      <xsl:call-template name="AttributeErzeugen"> 
       <xsl:with-param name="pAttr" select="$vInvoiceElement/Attribute"/> 
      </xsl:call-template> 
     </xsl:if> 
     <xsl:apply-templates/> 
     </xsl:copy> 
    </xsl:template> 
    <xsl:template name="AttributeErzeugen"> 
     <xsl:param name="pAttr"/> 
     <xsl:for-each select="$pAttr"> 
     <xsl:attribute name="{@name}"><xsl:value-of select="."/></xsl:attribute> 
     </xsl:for-each> 
    </xsl:template> 
</xsl:stylesheet> 
+0

您需要提供参与转换XML文档 - 否则人们无法确定的处理做了什么。 – 2010-05-04 12:58:48

+0

你也应该清楚你的属性是什么意思。代码实际上将外部文档中的元素作为具有相同名称的属性复制到当前文档中的元素。我在这里没有看到任何错误。 – newtover 2010-05-04 14:03:16

回答