2010-05-04 86 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

回答

相關問題