input:
<DS>
<TL>
<msg>
<output_getquerydata>
<queries>
<query name="q1">
<parameters>
<parameter name="id">906OREA</parameter>
</parameters>
<results>
<record>
<column name="actionState">sdss</column>
</record>
</results>
</query>
<query name="q2">
<parameters>
<parameter name="resCode">CTL</parameter>
<parameter name="prodCode">89CMID</parameter>
<parameter name="pos">1,2,4,3</parameter>
</parameters>
<results>
<record id="1">
<column name="position">1</column>
<column name="ExternalProductId"/>
</record>
<record id="9">
<column name="position"/>
<column name="ExternalProductId">316442</column>
</record>
</results>
</query>
<query name="q2">
<parameters>
<parameter name="resCode">CTL</parameter>
<parameter name="prodCode">91VPRM</parameter>
<parameter name="pos">1,2,4,3</parameter>
</parameters>
<results>
<record id="1">
<column name="position"/>
<column name="ExternalProductId">316495</column>
</record>
</results>
</query>
</queries>
</output_getquerydata>
</msg>
<TL>
<ArticleNr>89CMID</ArticleNr>
</TL>
<TL>
<ArticleNr>89CMID</ArticleNr>
</TL>
<TL>
<ArticleNr>89CMID</ArticleNr>
</TL>
<TL>
<ArticleNr>91VPRM</ArticleNr>
</TL>
</TL>
</DS>
XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="Article" match="tLoading" use="./ArticleNr"/>
<xsl:key name="prod" match="query[@name='q2']/results/record" use="./column[@name='ExternalProductId'][node()]"/>
<xsl:template match="DS">
<msglist>
<xsl:for-each select="./TL[./msg/output_getquerydata/queries/query/results/record/column[@name='actionState'] !='finished'] ">
<xsl:variable name="distinctArticle" select="//TL[string(ArticleNr)][count(. | key('Article',ArticleNr)[1]) = 1]"/>
<msg>
<xsl:for-each select="$distinctArticle">
<load-part>
<!--I need here the value from column[@name='ExtPR'], that has parameter[@name='prodCode']=the current TL articleNr node.
-->
<productId>
<xsl:value-of select="key('prod',column[@name='ExternalProductId'])"/>
</productId>
<!--something-->
</load-part>
</xsl:for-each>
</msg>
</xsl:for-each>
</msglist>
</xsl:template>
</xsl:stylesheet>
期望的输出:
<msglist>
<msg>
<load-part>
<productId>316442</productId>
</load-part>
<load-part>
<productId>316442</productId>
</load-part>
<load-part>
<productId>316442</productId>
</load-part>
<load-part>
<productId>316495</productId>
</load-part>
</msg>
</msglist>
我需要在productID
节点中,来自column[@name='ExternalProductId']
的值,该值具有parameter[@name='prodCode']=the current <TL><ArticleNr>
节点。 我知道我输入的这个"对于每个"代码只返回两个值,因为我正在寻找不同的值,所以我想我会尝试使用键,但我不确定我错过了什么。
谢谢
编辑为正确的输出值
首先,您的Article
键看起来是错误的(在您的问题的上下文中(,因为您的 XML 中没有tLoading
元素。所以应该是这个...
<xsl:key name="Article" match="TL" use="ArticleNr"/>
但是要回答您的直接问题,您需要像这样定义您的prod
键
<xsl:key name="prod"
match="query[@name='q2']/results/record"
use="../../parameters/parameter[@name='prodCode']"/>
然后,要查找它,请执行此操作...
<xsl:value-of select="key('prod', ArticleNr)/column[@name='ExternalProductId']"/>
或者也许这个,因为他们的"q2"查询有两个外部产品ID...
<xsl:value-of select="key('prod', ArticleNr)/column[@name='ExternalProductId'][. != '']"/>
试试这个 XSLT(它保留了你独特的检查,所以只输出两行(
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:key name="Article" match="TL" use="ArticleNr"/>
<xsl:key name="prod" match="query[@name='q2']/results/record" use="../../parameters/parameter[@name='prodCode']"/>
<xsl:template match="DS">
<msglist>
<xsl:for-each select="./TL[./msg/output_getquerydata/queries/query/results/record/column[@name='actionState'] !='finished'] ">
<xsl:variable name="distinctArticle" select="//TL[string(ArticleNr)][count(. | key('Article',ArticleNr)[1]) = 1]"/>
<msg>
<xsl:for-each select="$distinctArticle">
<load-part>
<productId>
<xsl:value-of select="ArticleNr" />
<xsl:text> - </xsl:text>
<xsl:value-of select="key('prod', ArticleNr)/column[@name='ExternalProductId'][. != '']"/>
</productId>
</load-part>
</xsl:for-each>
</msg>
</xsl:for-each>
</msglist>
</xsl:template>
</xsl:stylesheet>