我是 xslt 的新手并试图创建一个 XSLT ,我正在调用另一个模板并将参数值传递给它但是不知何故,目标模板的参数变量中出现了空白值。
这是简化的示例 xml 文件:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<TCXML xmlns="http://www.tcxml.org/Schemas/TCXMLSchema">
<BOMWindow elemId="id62" revision_rule="id60" top_line="id2">
<GSIdentity elemId="id1" label="a00pC7EtM1CZ7D"/>
</BOMWindow>
<IMAN_Drawing elemId="id78" owning_site="id4" primary_object="#id21" secondary_object="#id25" user_data="">
<GSIdentity elemId="id50" label="R8D9sTvgBT4jNA"/>
</IMAN_Drawing>
<IMAN_Drawing elemId="id79" owning_site="#id4" primary_object="#id22" secondary_object="#id26" user_data="">
<GSIdentity elemId="id56" label="R8D9sTfVBT4jNA"/>
</IMAN_Drawing>
<IMAN_Drawing elemId="id80" owning_site="#id4" primary_object="#id20" secondary_object="#id24" user_data="">
<GSIdentity elemId="id44" label="R8A9sTu6BT4jNA"/>
</IMAN_Drawing>
<UGPART creation_date="2012-06-05T09:25:30Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id117" format_used="PART" gov_classification="" object_name="Test" owning_organization="" >
<GSIdentity elemId="id21" label="RXM9sPifBT4jNA"/>
</UGPART>
<UGPART creation_date="2012-06-05T09:25:30Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id117" format_used="PART" gov_classification="" object_name="Test2" owning_organization="" >
<GSIdentity elemId="id20" label="R3K9sPifBT4jNA"/>
</UGPART>
<UGPART creation_date="2012-06-05T09:25:30Z" date_released="2012-06-05T09:25:33Z" ead_paragraph="" elemId="id117" format_used="PART" gov_classification="" object_name="Test3" owning_organization="" >
<GSIdentity elemId="id22" label="xuO9sPifBT4jNA"/>
</UGPART>
在 XML 中有 3 个 IMAN_Drawing 标记和 3 个 UGPART 标记
这是我的xslt
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:plm="http://www.tcxml.org/Schemas/TCXMLSchema" version="1.0">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/plm:TCXML/plm:IMAN_Drawing">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:for-each select="/plm:TCXML/plm:IMAN_Drawing">
<xsl:variable name="currentSecObjectId" select="@secondary_object"/>
<xsl:variable name="RefSecObjectId" select="substring($currentSecObjectId,2)"/>
<xsl:variable name="currentPrimaryObjectId" select="/plm:TCXML/plm:IMAN_Drawing/@primary_object"/>
<xsl:variable name="RefPrimaryObjectId" select="substring($currentPrimaryObjectId,2)"/>
<xsl:call-template name="UGPart">
<xsl:with-param name="PriId" select="$RefPrimaryObjectId"/>
</xsl:call-template>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="/plm:TCXML/plm:UGPART" name="UGPart">
<xsl:param name="PriId"/>
<xsl:copy>
<xsl:if test="@object_name="'Test'">
<xsl:attribute name="owning_organization">
<xsl:value-of select="$PriId"/>
</xsl:attribute>
</xsl:if>
<xsl:copy-of select="@*[not(name()='owning_organization')]" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
但输出是: owning_organization=""
预期结果是:它应该更新我从模板 1 传递的 owning_organization 属性,当它的 @object_name="'Test'" 时,UGPART 的 value = $RefPrimaryObjectId
这里出了什么问题?为什么 $RefPrimaryObjectId" 值没有出现在第二个模板中。