The following xml document is being looked up by an XSLT:
<?xml version="1.0"?>
<Generic>
<SalesOrgProperties_HashMap>
<item key="1003" value="3660,00,C0"/>
<item key="1005" value="3670,00,L0"/>
<item key="1214" value="4200,00,L0"/>
</SalesOrgProperties_HashMap>
<CondType_PriceListDiscount_HashMap>
<item key="1003" value="ZL99"/>
<item key="1005" value="ZL99"/>
<item key="1214" value="ZL99"/>
<item key="1227" value="ZL99"/>
</CondType_PriceListDiscount_HashMap>
<CondType_NetAmount_HashMap>
<item key="1003" value="ZAF2"/>
<item key="1005" value="ZAF2"/>
<item key="1214" value="ZPVP"/>
<item key="1227" value="ZAF2"/>
</CondType_NetAmount_HashMap>
<CondType_GrossPrice_HashMap>
<!--<item key="1003" value="ZHTI"/>-->
<item key="1005" value="ZHTI"/>
<item key="1214" value="ZHTI"/>
<item key="1227" value="ZHTI"/>
</CondType_GrossPrice_HashMap>
</Generic>
The blocks that employs the lookup operation are these:
<xsl:key name="SO_ReplaceFunction" match="item" use="@key"/>
<xsl:variable name="SO_Properties" select="document($LookupDocument)/Generic/SalesOrgProperties_HashMap"/>
<xsl:key name="CondType_PriceListDiscount_ReplaceFunction" match="item" use="@key"/>
<xsl:variable name="CondType_PriceListDiscount_Properties" select="document($LookupDocument)/Generic/CondType_PriceListDiscount_HashMap"/>
<xsl:key name="CondType_NetAmount_ReplaceFunction" match="item" use="@key"/>
<xsl:variable name="CondType_NetAmount_Properties" select="document($LookupDocument)/Generic/CondType_NetAmount_HashMap"/>
<xsl:key name="CondType_GrossPrice_ReplaceFunction" match="item" use="@key"/>
<xsl:variable name="CondType_GrossPrice_Properties" select="document($LookupDocument)/Generic/CondType_GrossPrice_HashMap"/>
And the defined templates:
<xsl:template match="SalesOrgProperties_HashMap">
<xsl:param name="valueToLookup"/>
<xsl:value-of select="key('SO_ReplaceFunction', $valueToLookup)/@value"/>
</xsl:template>
<xsl:template match="CondType_PriceListDiscount_HashMap">
<xsl:param name="valueToLookup"/>
<xsl:value-of select="key('CondType_PriceListDiscount_ReplaceFunction', $valueToLookup)/@value"/>
</xsl:template>
<xsl:template match="CondType_NetAmount_HashMap">
<xsl:param name="valueToLookup"/>
<xsl:value-of select="key('CondType_NetAmount_ReplaceFunction', $valueToLookup)/@value"/>
</xsl:template>
<xsl:template match="CondType_GrossPrice_HashMap">
<xsl:param name="valueToLookup"/>
<xsl:value-of select="key('CondType_GrossPrice_ReplaceFunction', $valueToLookup)/@value"/>
</xsl:template>
And an example application:
<xsl:apply-templates select="$CondType_PriceListDiscount_Properties">
<xsl:with-param name="valueToLookup" select="$salesOrg"/>
</xsl:apply-templates>
The output seen is:
However, I was expecting this: ZL99 for an input of 1214.
Any idea what am I wrong? Thanks.
The following xml document is being looked up by an XSLT:
<?xml version="1.0"?>
<Generic>
<SalesOrgProperties_HashMap>
<item key="1003" value="3660,00,C0"/>
<item key="1005" value="3670,00,L0"/>
<item key="1214" value="4200,00,L0"/>
</SalesOrgProperties_HashMap>
<CondType_PriceListDiscount_HashMap>
<item key="1003" value="ZL99"/>
<item key="1005" value="ZL99"/>
<item key="1214" value="ZL99"/>
<item key="1227" value="ZL99"/>
</CondType_PriceListDiscount_HashMap>
<CondType_NetAmount_HashMap>
<item key="1003" value="ZAF2"/>
<item key="1005" value="ZAF2"/>
<item key="1214" value="ZPVP"/>
<item key="1227" value="ZAF2"/>
</CondType_NetAmount_HashMap>
<CondType_GrossPrice_HashMap>
<!--<item key="1003" value="ZHTI"/>-->
<item key="1005" value="ZHTI"/>
<item key="1214" value="ZHTI"/>
<item key="1227" value="ZHTI"/>
</CondType_GrossPrice_HashMap>
</Generic>
The blocks that employs the lookup operation are these:
<xsl:key name="SO_ReplaceFunction" match="item" use="@key"/>
<xsl:variable name="SO_Properties" select="document($LookupDocument)/Generic/SalesOrgProperties_HashMap"/>
<xsl:key name="CondType_PriceListDiscount_ReplaceFunction" match="item" use="@key"/>
<xsl:variable name="CondType_PriceListDiscount_Properties" select="document($LookupDocument)/Generic/CondType_PriceListDiscount_HashMap"/>
<xsl:key name="CondType_NetAmount_ReplaceFunction" match="item" use="@key"/>
<xsl:variable name="CondType_NetAmount_Properties" select="document($LookupDocument)/Generic/CondType_NetAmount_HashMap"/>
<xsl:key name="CondType_GrossPrice_ReplaceFunction" match="item" use="@key"/>
<xsl:variable name="CondType_GrossPrice_Properties" select="document($LookupDocument)/Generic/CondType_GrossPrice_HashMap"/>
And the defined templates:
<xsl:template match="SalesOrgProperties_HashMap">
<xsl:param name="valueToLookup"/>
<xsl:value-of select="key('SO_ReplaceFunction', $valueToLookup)/@value"/>
</xsl:template>
<xsl:template match="CondType_PriceListDiscount_HashMap">
<xsl:param name="valueToLookup"/>
<xsl:value-of select="key('CondType_PriceListDiscount_ReplaceFunction', $valueToLookup)/@value"/>
</xsl:template>
<xsl:template match="CondType_NetAmount_HashMap">
<xsl:param name="valueToLookup"/>
<xsl:value-of select="key('CondType_NetAmount_ReplaceFunction', $valueToLookup)/@value"/>
</xsl:template>
<xsl:template match="CondType_GrossPrice_HashMap">
<xsl:param name="valueToLookup"/>
<xsl:value-of select="key('CondType_GrossPrice_ReplaceFunction', $valueToLookup)/@value"/>
</xsl:template>
And an example application:
<xsl:apply-templates select="$CondType_PriceListDiscount_Properties">
<xsl:with-param name="valueToLookup" select="$salesOrg"/>
</xsl:apply-templates>
The output seen is:
However, I was expecting this: ZL99 for an input of 1214.
Any idea what am I wrong? Thanks.
Share Improve this question edited Mar 14 at 11:29 Srii asked Mar 14 at 11:24 SriiSrii 5994 gold badges8 silver badges25 bronze badges 2- Don't post pictures of data and code, post the actual XML to make it easier for people to analyze/test and give you helpful answers. Nobody wants to spend time transcribing XML from a picture. – Mads Hansen Commented Mar 14 at 11:28
- @MadsHansen - done, thx – Srii Commented Mar 14 at 11:30
2 Answers
Reset to default 3You could also change
<xsl:template match="CondType_PriceListDiscount_HashMap">
<xsl:param name="valueToLookup"/>
<xsl:value-of select="key('CondType_PriceListDiscount_ReplaceFunction', $valueToLookup)/@value"/>
</xsl:template>
to
<xsl:template match="CondType_PriceListDiscount_HashMap">
<xsl:param name="valueToLookup"/>
<xsl:value-of select="key('CondType_PriceListDiscount_ReplaceFunction', $valueToLookup, .)/@value"/>
</xsl:template>
if I understand your document structure and templates correctly.
It might be possible that way to use a single key and a single template
<xsl:template match="SalesOrgProperties_HashMap | CondType_PriceListDiscount_HashMap | CondType_NetAmount_HashMap | CondType_GrossPrice_HashMap">
<xsl:param name="valueToLookup"/>
<xsl:value-of select="key('CondType_PriceListDiscount_ReplaceFunction', $valueToLookup, .)/@value"/>
</xsl:template>
Your xsl:key/@match
expressions are too generic. It is matching any/all of the item
elements and you need to restrict it to the ones that are children of the specific HashMap element.
For instance:
<xsl:key name="CondType_PriceListDiscount_ReplaceFunction"
match="CondType_PriceListDiscount_HashMap/item"
use="@key"/>