Link to home
Start Free TrialLog in
Avatar of chrisV
chrisV

asked on

Really short quick question!!!

How can can I say:
if the attribute of my <section> tag (got with "../section/section") has an attribute called "archive" and it's = "true" then "do something..."
                  
for example the section tag will look like this
                  
<section id="111" archive="true">
....
....
.....
<section>
Avatar of dfiala13
dfiala13

in xsl I assume?

<xsl:for-each select="../section/section" />

<xsl:if test="@archive = 'true' />

</xsl:if>

</xsl:for-each>
shuld be <xsl:if test="@archive = 'true'" />
Avatar of chrisV

ASKER

Sorry mate but with this code:
_____________
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

                  <xsl:when test="../section/section">
                  <xsl:if test="@archive = 'true'" />
                        <a>
                        
                              <xsl:attribute name="href">
                                    <xsl:value-of select="dirname"/>
                              </xsl:attribute>
                              <xsl:value-of select="title"/>
                        </a><br/>
                  </xsl:if>
                  
                  </xsl:when>
_________________________

I get this error:
End tag 'xsl:if' does not match the start tag 'xsl:when'. Error processing resource 'file:///C:/Inetpub/wwwroot/inc/hs~premium_transform.xsl'. Line 13, Position 6

   </xsl:if>

______________
Do you know what is wrong?
ASKER CERTIFIED SOLUTION
Avatar of dfiala13
dfiala13

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chrisV

ASKER

Oh if you are still there is there a way of saying if an attribute exists

Something like:
.....
         ifexists(@archive) then..
....

bacause some <section> tags are like:
<section id="111">....</section>

and some are like:
<section id="222" archive="true" >....</section>

and some are like:
<section id="222" archive="false" >....</section>

Sorry!! and thanks!!
xsl is very forgiving so you can just check if the value of the attribute has any length, if it doesn't it doesn't exist (or has no value):

<xsl:if test="string-length(@archive) &gt; 0>

</xsl:if>

here's a handy reference that I've used for years
http://nwalsh.com/docs/tutorials/xsl/xsl/slides.html
Avatar of chrisV

ASKER

Thanks mate, have a good weekend