Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - XSL Problem >Thread Next - Re: XSL Problem Re: XSL ProblemTo: NULL Date: 2/2/2006 5:49:00 PM "infiniti" <jainamber@g...> wrote in message
news:1138901667.255131.172410@z......
Hi,
I am trying to transform this xml section using xsl, but there
is a glitch in the xsl file which I do not know how to rectify. Any
help is appreciated.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<RelatedKeyword><Common>anushka</Common><Searches>1032</Searches></RelatedKeyword>
<RelatedKeyword><Common>anushka
spa</Common><Searches>301</Searches></RelatedKeyword>
<RelatedKeyword><Common>anushka day
spa</Common><Searches>81</Searches></RelatedKeyword>
<GetMarketStateResponse searchTerm="anushka">
<Listing rank="1" bid="0.31" market="US"/>
<Listing rank="2" bid="0.22" market="US"/>
<Listing rank="3" bid="0.20" market="US"/>
<Listing rank="4" bid="0.10" market="US"/>
</GetMarketStateResponse>
<GetMarketStateResponse searchTerm="anushka spa">
<Listing rank="1" bid="0.11" market="US"/>
<Listing rank="2" bid="0.22" market="US"/>
<Listing rank="3" bid="0.40" market="US"/>
<Listing rank="4" bid="0.34" market="US"/>
</GetMarketStateResponse>
</xml>
XSL:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select="xml" />
</xsl:template>
<xsl:variable name="basename" select='bid' />
<xsl:template match="xml">
<xml>
<xsl:for-each select="./GetMarketStateResponse">
<row>
<xsl:attribute name="RelatedKeyword">
<xsl:value-of select="@searchTerm" />
</xsl:attribute>
<xsl:variable name="node"
select="//RelatedKeyword/Common[@name=current()/@searchTerm]" />
<xsl:attribute name="Searches">
<xsl:value-of select="$node/Searches" />
</xsl:attribute>
<xsl:for-each select="./Listing">
<xsl:variable name="rank" select="@rank" />
<xsl:attribute name="bid{$rank}">
<xsl:value-of select="@bid" />
</xsl:attribute>
</xsl:for-each>
</row>
</xsl:for-each>
</xml>
</xsl:template>
</xsl:stylesheet>
Output that I am getting:
<?xml version="1.0" encoding="UTF-8"?>
<xml>
<row RelatedKeyword="anushka" Searches="" bid1="0.31" bid2="0.22"
bid3="0.20" bid4="0.10"/>
<row RelatedKeyword="anushka spa" Searches="" bid1="0.11" bid2="0.22"
bid3="0.40" bid4="0.34"/>
<row RelatedKeyword="anushka day spa" Searches=""/>
</xml>
As you can see, that I am not getting the value for the Searches
attribute. I am not too familiar with Xpath expressions.
Thanks for your help.
Amber
When you set the node variable you use:
//RelatedKeyword/Common[@name=current()/@searchTerm]
<Common> doesn't have a name attribute.
I think you want:
//RelatedKeyword/Common[.=current()/@searchTerm]
Or better still to save processing:
/xml/RelatedKeyword/Common[.=current()/@searchTerm]
Technically the use of xml as an element name is disallowed.
--
Joe Fawcett - XML MVP
https://mvp.support.microsoft.com/profile=8AA9D5F5-E1C2-44C7-BCE8-8741D22D17A5
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
