0
我得到了一些帶有一些元素的xml文件。對於其中的一些,它是一個參數xml文件中的一個有效值以及其他一些元素。 如果元素名稱匹配,我想從parm-file中將這些其他元素作爲參數添加到輸出文件。 (屬性應如果一個元素「InvoiceHeader」源代碼中的XML只存在產生。如果source-Element在參數文件中,XSLT生成屬性
這裏是我的代碼...
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:variable name="rpl" select="document('ParamInvoice.xml')"></xsl:variable>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates></xsl:apply-templates>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:if test="$rpl/StoraInvoice/local-name()">
<xsl:call-template name="AttributeErzeugen">
<xsl:with-param name="attr" select="$rpl/StoraInvoice/local-name()"></xsl:with-param>
</xsl:call-template>
</xsl:if>
<xsl:apply-templates></xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template name="AttributeErzeugen">
<xsl:param name="attr"></xsl:param>
<xsl:for-each select="$attr">
<xsl:attribute name="{Attibute/@name}"><xsl:value-of select="."></xsl:value- of></xsl:attribute>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
這裏帕拉姆文件
<?xml version="1.0" encoding="UTF-8"?>
<StoraInvoice>
<InvoiceHeader>
<Attribute name="Fuehrend">YYY</Attribute>
<Attribute name="Feld">FFFF</Attribute>
<Attribute name="Format">XYZXYZ</Attribute>
</InvoiceHeader>
</StoraInvoice>
齊格弗裏德
很好的問題(+1)。查看我的答案以獲得解決方案。 :) – 2010-04-29 13:29:23