![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries [Thread Prev] >Thread Next - Re: XSL Problem XSL ProblemTo: NULL Date: 2/2/2006 9:34:00 AM 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=3D"1.0" encoding=3D"UTF-8"?>
<xml>
<RelatedKeyword><Common>anushka</Common><Searches>1032</Searches></RelatedK=
=ADeyword>
<RelatedKeyword><Common>anushka
spa</Common><Searches>301</Searches></RelatedKeyword>
<RelatedKeyword><Common>anushka day
spa</Common><Searches>81</Searches></RelatedKeyword>
<GetMarketStateResponse searchTerm=3D"anushka">
<Listing rank=3D"1" bid=3D"0.31" market=3D"US"/>
<Listing rank=3D"2" bid=3D"0.22" market=3D"US"/>
<Listing rank=3D"3" bid=3D"0.20" market=3D"US"/>
<Listing rank=3D"4" bid=3D"0.10" market=3D"US"/>
</GetMarketStateResponse>
<GetMarketStateResponse searchTerm=3D"anushka spa">
<Listing rank=3D"1" bid=3D"0.11" market=3D"US"/>
<Listing rank=3D"2" bid=3D"0.22" market=3D"US"/>
<Listing rank=3D"3" bid=3D"0.40" market=3D"US"/>
<Listing rank=3D"4" bid=3D"0.34" market=3D"US"/>
</GetMarketStateResponse>
</xml>
XSL:
<?xml version=3D"1.0"?>
<xsl:stylesheet version=3D"1.0"
xmlns:xsl=3D"http://www.w3.org/1999/XSL/Transform">
<xsl:template match=3D"/">
<xsl:apply-templates select=3D"xml" />
</xsl:template>
<xsl:variable name=3D"basename" select=3D'bid' />
<xsl:template match=3D"xml">
<xml>
<xsl:for-each select=3D"./GetMarketStateResponse">
<row>
<xsl:attribute name=3D"RelatedKeyword">
<xsl:value-of select=3D"@searchTerm" />
</xsl:attribute>
<xsl:variable name=3D"node"
select=3D"//RelatedKeyword/Common[@name=3Dcurrent()/@searchTerm]" />
<xsl:attribute name=3D"Searches">
<xsl:value-of select=3D"$node/Searches" />
</xsl:attribute>
<xsl:for-each select=3D"./Listing">
<xsl:variable name=3D"rank" select=3D"@rank" />
<xsl:attribute name=3D"bid{$rank}">
<xsl:value-of select=3D"@bid" />
</xsl:attribute>
</xsl:for-each>
</row>
</xsl:for-each>
</xml>
</xsl:template>
</xsl:stylesheet>
Output that I am getting:
<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<xml>
<row RelatedKeyword=3D"anushka" Searches=3D"" bid1=3D"0.31" bid2=3D"0.22"
bid3=3D"0.20" bid4=3D"0.10"/>
<row RelatedKeyword=3D"anushka spa" Searches=3D"" bid1=3D"0.11" bid2=3D"0.2=
2"
bid3=3D"0.40" bid4=3D"0.34"/>
<row RelatedKeyword=3D"anushka day spa" Searches=3D""/>
</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.=20
Amber
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
