dany
dany

Reputation: 1881

How to parse XML using XSLT?

I have an XML with data as follows

<Item1>
  <item2>
    <Item3>111</Item3>
  <Item2>
</Item11>

To get the value 111 in Item3

<xsl:choose>
  <xsl:value-of select="Item1/Item2/Item3"/>
</xsl:choose>

In XSLT . Now I need to get the following:

<Product1>
  <Product2>
    <Product3 ValidYN="Y" ProducType="ABC">333</Product3>
    <Product3 ValidYN="Y" ProducType="DEF">444</Product3>
    <Product3 ValidYN="Y" ProducType="GHI">555</Product3>
  <Product12>
</Product1>

I need to take values 333 , 444 , 555 based on ProducType.How to do the same using XSLT

Upvotes: 1

Views: 4317

Answers (1)

JLRishe
JLRishe

Reputation: 101730

To select a node based on values in relation to it, you can use XPaths like this:

/Product1/Product2/Product3[@ValidYN = 'Y' and @ProductType = 'ABC']
/Product1/Product2/Product3[@ValidYN = 'Y' and @ProductType = 'DEF']
/Product1/Product2/Product3[@ValidYN = 'Y' and @ProductType = 'GHI']

the parts in [square brackets] are called "predicates."

Upvotes: 1

Related Questions