Arun
Arun

Reputation: 1472

Finding the data in a XML file using XSLT?

I have a XML and I need to find some data from that using xslt,Here is the XML

<root>

  <product>
    <id>134021</id>
    <bulkdiscountpricelist ></bulkdiscountpricelist>
    <webout extra="webout">1</webout>
  </product>

  <product>
    <id>134022</id>
    <bulkdiscountpricelist ></bulkdiscountpricelist>
    <webout extra="webout">0</webout>
  </product>

  <product>
    <id>134023</id>
    <bulkdiscountpricelist ></bulkdiscountpricelist>
    <webout extra="webout">1</webout>
  </product>


  <product>
    <id>134023</id>
    <bulkdiscountpricelist ></bulkdiscountpricelist>
    <webout extra="webout">0</webout>
  </product>

</root>

I want to check each id that has webout=1 using XSLT.

I tried a code but it is not working. My code is like

<xsl:value-of select="$result//product/id"/>

Upvotes: 1

Views: 66

Answers (3)

Borodin
Borodin

Reputation: 126722

It sounds like you need write a template like this

<xsl:template match="product[webout=1]">

to process all the relevant product elements.

We can't really help you more unless you describe what you are doing better. Where has your variable $result come from? You can't examine the contents of a variable like that unless you have the set-node extension in your XSLT transformer.

Upvotes: 2

vels4j
vels4j

Reputation: 11298

You can filter it by for-each like

<xsl:for-each select="/root/product[./webout=1]">
     <xsl:value-of select="id"/>
</xsl:for-each>

Upvotes: 0

Navin Rawat
Navin Rawat

Reputation: 3138

Use something like $result//product[webout=1]/id in xslt "1.1" otherwise use node-set() extension function to get output.

Upvotes: -1

Related Questions