XSL tag matching
-
XSL I'm making some output be bold only if a certain condition is true:
<xsl:if test="test"><b></xsl:if>
Now the problem is, all end tags must directly match up with their start tags (i.e. you can't do "<b><i></b></i>" - you have to do "<b><i></i></b><i></i>"). But I'm wanting the "<b>" tag only to be outputted only if the test condition is true. Short of having seperate block for each combination of <b>, <i>, <u>, etc, how do I do it? I've thought of using script to concatenate a <b>:
function GetTag(text)
GetTag=Chr(60) + text + Chr(62)
end functionOr can someone show me a better way?
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi -
XSL I'm making some output be bold only if a certain condition is true:
<xsl:if test="test"><b></xsl:if>
Now the problem is, all end tags must directly match up with their start tags (i.e. you can't do "<b><i></b></i>" - you have to do "<b><i></i></b><i></i>"). But I'm wanting the "<b>" tag only to be outputted only if the test condition is true. Short of having seperate block for each combination of <b>, <i>, <u>, etc, how do I do it? I've thought of using script to concatenate a <b>:
function GetTag(text)
GetTag=Chr(60) + text + Chr(62)
end functionOr can someone show me a better way?
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma GandhiThe 'politically correct' way is probably to use the xsl:element tag e.g.
xsl:choose
<xsl:when test="test">
<xsl:element name="b">
Your Content
</xsl:element>
</xsl:when>
xsl:otherwise
Your Content
</xsl:otherwise>
</xsl:choose>This is easy enough if your content is in another rule or a function or something - not so easy otherwise...but it does make sure you've got all tags paired correctly. Stuart Dootson 'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
-
The 'politically correct' way is probably to use the xsl:element tag e.g.
xsl:choose
<xsl:when test="test">
<xsl:element name="b">
Your Content
</xsl:element>
</xsl:when>
xsl:otherwise
Your Content
</xsl:otherwise>
</xsl:choose>This is easy enough if your content is in another rule or a function or something - not so easy otherwise...but it does make sure you've got all tags paired correctly. Stuart Dootson 'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
-
Stuart Dootson wrote: to use the xsl:element tag Now why didn't I remember that one! THANKS!!! :) :rose:
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma GandhiAnd also remember xsl:attribute when you need to add attributes to elements :) Stuart Dootson 'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
-
And also remember xsl:attribute when you need to add attributes to elements :) Stuart Dootson 'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
Yep. You can bet I immediately looked up xsl:element and its related tags on MSDN as soon as I saw this! Thanks again!
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi -
The 'politically correct' way is probably to use the xsl:element tag e.g.
xsl:choose
<xsl:when test="test">
<xsl:element name="b">
Your Content
</xsl:element>
</xsl:when>
xsl:otherwise
Your Content
</xsl:otherwise>
</xsl:choose>This is easy enough if your content is in another rule or a function or something - not so easy otherwise...but it does make sure you've got all tags paired correctly. Stuart Dootson 'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
or even
<xsl:choose> <xsl:when test="test"> <b>Your Content</b> </xsl:when> <xsl:otherwise>Your Content</xsl:otherwise></xsl:choose>
"When the only tool you have is a hammer, a sore thumb you will have."
-
or even
<xsl:choose> <xsl:when test="test"> <b>Your Content</b> </xsl:when> <xsl:otherwise>Your Content</xsl:otherwise></xsl:choose>
"When the only tool you have is a hammer, a sore thumb you will have."
I did say 'the politically correct way'....;P Stuart Dootson 'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
-
or even
<xsl:choose> <xsl:when test="test"> <b>Your Content</b> </xsl:when> <xsl:otherwise>Your Content</xsl:otherwise></xsl:choose>
"When the only tool you have is a hammer, a sore thumb you will have."
-
This is precicsely what I was trying to avoid. ;)
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhian even better way would be (xhtml & css2):
<span> <xsl:if test="test"> <xsl:attribute name="style">font-weight: bold</xsl:attribute> </xsl:if> Your Content </span>
hope this helps
"When the only tool you have is a hammer, a sore thumb you will have."
-
an even better way would be (xhtml & css2):
<span> <xsl:if test="test"> <xsl:attribute name="style">font-weight: bold</xsl:attribute> </xsl:if> Your Content </span>
hope this helps
"When the only tool you have is a hammer, a sore thumb you will have."