通过XSLT内的xml节点迭代
使用xslt 1.0。我正在调用一个java函数getTierByBundleId,它返回到xml以下。我想遍历每个使用的每个层。我怎样才能做到这一点通过XSLT内的xml节点迭代
<xsl:variable name="varTierList" select="testclass:getTierByBundleId($bid,$ApplicationId)"/>
Xml returned by function getTierByBundleId
<TierList>
<Tier>
<TierId>1</TierId>
<Name>test</Name>
<Type>2</Type>
<Price>10</Price>
</Tier>
<Tier>
<TierId>2</TierId>
<Name>test</Name>
<Type>3</Type>
<Price>11</Price>
</Tier>
</TierList>
这里的时候,我试图做的xsl:对于每一个在具有我收到编译错误的XML变量。如何访问各阶层从变量$ varTierList
<xsl:for-each select="$varTierList/TierList/Tier">
<TierId><xsl:for each"Tierid"/>
</xsl:for-each
下面是这一代上述TierList XML
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:foxtelclass="test.GetOrderQuote" exclude-result-prefixes="foxtelclass" extension-element-prefixes="testclass">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:if test="count(/ROWSET/ROW) > 0">
<TierList>
<xsl:for-each select="/ROWSET/ROW">
<Tier>
<TierId><xsl:value-of select="TIER_ID" /></TierId>
<Name><xsl:value-of select="NAME" /></Name>
<Type><xsl:value-of select="TIER_TYPE" /></Type>
<Price><xsl:value-of select="PRICE" /></Price>
</Tier>
</xsl:for-each>
</TierList>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
<xsl:for-each select="$varTierList/TierList/Tier"> is throwing the error message
Here is the full xslt
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:testclass="test.GetOrderQuote"
xmlns:ext="http://exslt.org/common" exclude-result-prefixes="testclass" extension-
element-prefixes="testclass">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="ApplicationId"/>
<xsl:template match="/">
<ServiceList>
<xsl:variable name="unique-list" select="//ROWSET/ROW/SERVICE_ID
[not(.=following::SERVICE_ID)]"/>
<xsl:for-each select="$unique-list">
<xsl:if test=".!=0">
<Service>
<xsl:variable name="Sid" select="."/>
<ServiceInternalId>
<xsl:value-of select="."/>
</ServiceInternalId>
<BundleList>
<xsl:variable name="unique-
bundle" select="//SERVICE_ID/../BUNDLE_ID[not(.=following::BUNDLE_ID)]"/>
<xsl:for-each
select="$unique-bundle">
<xsl:variable
name="bid" select="."/>
<xsl:if
test="count(/ROWSET/ROW/SERVICE_ID[text()=$Sid]/../BUNDLE_ID[text()=$bid])> 0">
<Bundle>
<Bundle_Id>
<xsl:value-of select="$bid"/>
</Bundle_Id>
<Type>
<xsl:value-of select="../BUNDLE_TYPE"/>
</Type>
<Name>
<xsl:value-of select="../BUNDLE_NAME"/>
</Name>
<Price>
<xsl:value-of select="../BUNDLE_PRICE"/>
</Price>
<xsl:variable name="varTierList" select="testclass:getTierByBundleId
($bid,$ApplicationId)"/>
<test>
<xsl:value-of select="$varTierList"/>
</test>
<xsl:for-each select="$varTierList/TierList/Tier"><!--line causing error-->
<TierId>
<xsl:value-of select="TierId"/>
</TierId>
</xsl:for-each>
</Bundle>
</xsl:if>
</xsl:for-each>
</BundleList>
</Service>
</xsl:if>
</xsl:for-each>
</ServiceList>
</xsl:template>
</xsl:stylesheet>
Below is the text from test node which what is xml variable varTierList contains
<test><TierList>
<Tier>
<TierId>109</TierId>
<Name>Boxes</Name>
<Type>10</Type>
<Price>10</Price>
</Tier>
</TierList>
</test>
Please find below input xml
<ROWSET> <ROW> <SET_ID>0</SET_ID> <SET_DATE>2014-11-09 00:00:00.0</SET_DATE> <BUNDLE_NAME>Test</BUNDLE_NAME> <BUNDLE_ID>131</BUNDLE_ID> <BUNDLE_PRICE>30</BUNDLE_PRICE> <BUNDLE_TYPE>3</BUNDLE_TYPE> <BUNDLECOMPONENT_LIST>101100</BUNDLECOMPONENT_LIST> <PACKAGE>10015</PACKAGE> <PACKAGE_TYPE>5</PACKAGE_TYPE> <COMPONENT>101100</COMPONENT> <PRODUCT_DESC>World Movies</PRODUCT_DESC> <RATE_AMOUNT>10</RATE_AMOUNT> <DISCOUNT_AMOUNT>0</DISCOUNT_AMOUNT> <SERVICE_ID>98683812</SERVICE_ID> <CHARGE_TYPE>RC</CHARGE_TYPE> <GUID_TOKEN>053944D794856E3FE0540010E00D30B8</GUID_TOKEN> <NRC_LINE_ID>0</NRC_LINE_ID> <TIERID>11</TIERID> </ROW> <ROW> <SET_ID>0</SET_ID> <SET_DATE>2014-11-09 00:00:00.0</SET_DATE> <BUNDLE_NAME>Optional test</BUNDLE_NAME> <BUNDLE_ID>131</BUNDLE_ID> <BUNDLE_PRICE>30</BUNDLE_PRICE> <BUNDLE_TYPE>3</BUNDLE_TYPE> <BUNDLECOMPONENT_LIST>101100</BUNDLECOMPONENT_LIST> <PACKAGE>10015</PACKAGE> <PACKAGE_TYPE>5</PACKAGE_TYPE> <COMPONENT>101103</COMPONENT> <PRODUCT_DESC>RAI International</PRODUCT_DESC> <RATE_AMOUNT>20</RATE_AMOUNT> <DISCOUNT_AMOUNT>0</DISCOUNT_AMOUNT> <SERVICE_ID>98683812</SERVICE_ID> <CHARGE_TYPE>RC</CHARGE_TYPE> <GUID_TOKEN>053944D794856E3FE0540010E00D30B8</GUID_TOKEN> <NRC_LINE_ID>0</NRC_LINE_ID> <TIERID>14</TIERID> </ROW> </ROWSET>
希望这有助于 的XSLT,这是完全XSLT是在我的末尾没有显示任何编译错误
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:testclass="test.GetOrderQuote" xmlns:ext="http://exslt.org/common" exclude-result-prefixes="testclass">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="ApplicationId"/>
<xsl:template match="/">
<ServiceList>
<xsl:variable name="unique-list" select="//ROWSET/ROW/SERVICE_ID[not(.=following::SERVICE_ID)]"/>
<xsl:for-each select="$unique-list">
<xsl:if test=".!=0">
<Service>
<xsl:variable name="Sid" select="."/>
<ServiceInternalId>
<xsl:value-of select="."/>
</ServiceInternalId>
<BundleList>
<xsl:variable name="unique-bundle" select="//SERVICE_ID/../BUNDLE_ID[not(.=following::BUNDLE_ID)]"/>
<xsl:for-each select="$unique-bundle">
<xsl:variable name="bid" select="."/>
<xsl:if test="count(/ROWSET/ROW/SERVICE_ID[text()=$Sid]/../BUNDLE_ID[text()=$bid])> 0">
<Bundle>
<Bundle_Id>
<xsl:value-of select="$bid"/>
</Bundle_Id>
<Type>
<xsl:value-of select="../BUNDLE_TYPE"/>
</Type>
<Name>
<xsl:value-of select="../BUNDLE_NAME"/>
</Name>
<Price>
<xsl:value-of select="../BUNDLE_PRICE"/>
</Price>
<xsl:variable name="varTierList" select="testclass:getTierByBundleId($bid,$ApplicationId)"/>
<test>
<xsl:value-of select="$varTierList"/>
</test>
<xsl:for-each select="$varTierList/TierList/Tier">
<TierId>
<xsl:value-of select="TierId"/>
</TierId>
</xsl:for-each>
</Bundle>
</xsl:if>
</xsl:for-each>
</BundleList>
</Service>
</xsl:if>
</xsl:for-each>
</ServiceList>
</xsl:template>
</xsl:stylesheet>
我仍然收到编译错误,下面是我的代码'
那么你可以发布你的整个xslt,因为我没有看到你发布的任何语法错误在评论 – Saurav 2014-10-12 08:41:22
请找到上面完整的xslt和xml,其中变量包含。谢谢。 – user3366906 2014-10-12 11:13:47
如何回合分享确切的错误讯息?这将节省一些猜测。 – 2014-10-10 05:56:24
请发现以下错误消息javax.xml.transform.TransformerException:javax.xml.transform.TransformerConfigurationException:无法编译样式表 \t at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl .java:735) \t at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:336) – user3366906 2014-10-11 00:43:52
当我尝试已发布的“完整”XSLT(这很难在没有输入XML的情况下做)!我得到两个错误,这两个错误都是由于'extension-¶element-prefixes'和'unique-¶bundle'中间的新行。 – 2014-10-12 13:00:35