0

Below is my xml sample. Here's what I want

  1. Loop through all cars
  2. If a car has a "Sport" style then display them, otherwise, ignore it

So in the example below, I will display Ferrari and 2 values of Convertible and Sport

I have <for-each>Car</end-for-each>. I want to check if a car has a style of "Sport" or not. How do I do that? Do I have to have another <for-each>Style</end-for-each> inside the <for-each>Car</end-for-each>? If I found a sport style then I'm initializing a variable and assign it such as

<?xdoxslt:set_variable($_XDOCTX, ’car’, 1)?> --- initialize to 1 if Sport style found
<?xdoxslt:get_variable($_XDOCTX, ’car’)?> --- retrieve

<Car>
<Brand>Honda</Brand>
<Style>Coupe</Style>
<Style>Sedan</Style>
</Car>
<Car>
<Brand>Ferrari</Brand>
<Style>Convertible</Style>
<Style>Sport</Style>
</Car>
Andy
  • 195
  • 2
  • 5
  • 13

1 Answers1

0

Here's what I want

  1. Loop through all cars
  2. If a car has a "Sport" style then display them, otherwise, ignore it

Normally, in XSLT you would approach this problem as:

  1. Select all cars with a "Sport" style;
  2. Display them.

For example:

<xsl:for-each select="Car[Style='Sport']">
    <!-- whatever "display" means -->
</xsl:for-each>

Alternatively, if "display" is the default for all nodes (e.g. if you're applying the identity transform template) you could apply an empty template matching all cars that do not have a "Sport" style, in order to suppress them.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51