我有这个输入:
<?xml version="1.0" encoding="utf-8"?>
<Native xmlns="http://www.cargowise.com/Schemas/Native/2011/11" version="2.0">
<Header>
<OwnerCode>VISSHIMEL</OwnerCode>
</Header>
</Native>
我的 xslt 中有一个声明的节点集:
<xsl:variable name="SupplierSCAC">
<m>Yellow</m>
<m>Red</m>
<m>Green</m>
</xsl:variable>
我正在尝试为此节点集执行每个操作并选择 OwnerCode 值“VISSHIMEL”,但由于某种原因,我的模板调用没有获得该值。预期输出为:
<TariffCollection>
Yellow
<test>VISSHIMEL</test>
</TariffCollection>
<TariffCollection>
Red
<test>VISSHIMEL</test>
</TariffCollection>
<TariffCollection>
Green
<test>VISSHIMEL</test>
</TariffCollection>**
然而,<test>
始终是空的。这是我的代码:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:var="http://schemas.microsoft.com/BizTalk/2003/var" exclude-result-prefixes="msxsl var s0 s1 exsl" version="1.0" xmlns:s0="http://www.cargowise.com/Schemas/Native/2011/11" xmlns:s1="http://www.cargowise.com/Schemas/Universal/2011/11" xmlns:exsl="http://exslt.org/common" >
<xsl:output omit-xml-declaration="yes" method="xml" version="1.0"/>
<xsl:template match="/">
<xsl:variable name="SupplierSCAC">
<m>Yellow</m>
<m>Red</m>
<m>Green</m>
</xsl:variable>
<xsl:for-each select="exsl:node-set($SupplierSCAC)/m">
<xsl:call-template name="Test">
<xsl:with-param name="SupplierSCAC" select="."/>
</xsl:call-template>
<!-- <xsl:apply-templates select="/s0:Native" > -->
<!-- <xsl:with-param name="SupplierSCAC" select="."/> -->
<!-- </xsl:apply-templates> -->
</xsl:for-each>
</xsl:template>
<xsl:template name="Test" match="/s0:Native">
<xsl:param name="SupplierSCAC"/>
<TariffCollection>
<xsl:value-of select="$SupplierSCAC"/>
<test>
<xsl:value-of select="s0:Header/s0:OwnerCode"/>
</test>
</TariffCollection>
</xsl:template>
</xsl:stylesheet>
我知道 for-each 并且参数已成功显示在输出中,但我不知道为什么我无法访问 xpath OwnerCode 的值。我尝试使用 apply-template ,但更糟糕的是因为我根本没有输出。如果您需要更多信息,请与我们联系。谢谢!