Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


XSL Problem

From: "infiniti" <jainamber@-----.--->
To: 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



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent