1

So I need to access a nested element in an if statement.

Below you can see an example of the XML I am using:

<Publication>
   <PubName>Avoid the Consumer Apps - How to Collaborate Securely and Productively in the Finance Sector</PubName>
   <Attributes>
    <Attribute>
     <AttributeName>Type</AttributeName>
     <Value>Webinar</Value>
     <ValueText>Webinar</ValueText>
    </Attribute>
   </Attributes>
  </Publication>

And here is the XSLT code I am using to try and get to the Webinar value:

<xsl:for-each select="TradePub.com/PublicationTable/Publication">
<xsl:if test="Attributes/Attribute/Value='Webinar'">
    <tr>
      <td><xsl:value-of select="PubName"/></td>
      <td><xsl:value-of select="PubCode"/></td>
    </tr>
</xsl:if>
</xsl:for-each>

But this returns nothings, so I am wondering how I can access the Value element?

2

1 Answer 1

2

Use a predicate on the Value element like this:

<xsl:for-each select="TradePub.com/PublicationTable/Publication">
    <xsl:if test="Attributes/Attribute[Value!='Webinar']">
        <tr>
        <td><xsl:value-of select="PubName"/></td>
        <td><xsl:value-of select="PubCode"/></td>
        </tr>
    </xsl:if>
</xsl:for-each>

Another problem why you don't get any output is that the IF-clause is FALSE in your sample. To get the desired output with the given sample, use

<xsl:if test="Attributes/Attribute[Value='Webinar']">

instead. Then, the output would be

<tr>
  <td>Avoid the Consumer Apps - How to Collaborate Securely and Productively in the Finance Sector</td>
  <td/>    <!-- No 'PubCode' element present -->
</tr>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.