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