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>
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>
shuld be <xsl:if test="@archive = 'true'" />
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/wwwroo t/inc/hs~p remium_tra nsform.xsl '. Line 13, Position 6
</xsl:if>
______________
Do you know what is wrong?
_____________
<?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/wwwroo
</xsl:if>
______________
Do you know what is wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!!
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(@archi ve) > 0>
</xsl:if>
here's a handy reference that I've used for years
http://nwalsh.com/docs/tutorials/xsl/xsl/slides.html
<xsl:if test="string-length(@archi
</xsl:if>
here's a handy reference that I've used for years
http://nwalsh.com/docs/tutorials/xsl/xsl/slides.html
ASKER
Thanks mate, have a good weekend
<xsl:for-each select="../section/section
<xsl:if test="@archive = 'true' />
</xsl:if>
</xsl:for-each>