Re: [xsl] Writing conditional statement based on attribute

Subject: Re: [xsl] Writing conditional statement based on attribute
From: Kamal Bhatt <kbhatt@xxxxxxxxx>
Date: Wed, 07 Feb 2007 08:36:01 +1100
llobash@xxxxxxxx wrote:
sure, sorry, more complete example:

<dsc type="combined">





again, I am trying to format scopecontent one way where @level="series" or
"subseries" and another where @level="file" or there is no attribute level.

thanks again,

Your description isn't particularly clear, so I just gave you an example where it replaces scopecontent with what you stated previously (or what I thought you wanted). In the future, you will find that if you give the input (as you have above) and the output you want produced, you will get a better response. This will hopefully be enough to help you on your way. This solution will only work if you have cXX elements, it won't work if the 'c' is a 'd'. If you are using a processor that supports regex processing (one that supports XSLT 2.0 or one that supports the exslt regex functions) you could tighten this processing with that.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"

<xsl:template match="dsc">
<xsl:template match="*[starts-with(local-name(), 'c') and (@level = 'subseries' or @level = 'series')]">
<xsl:element name="{name()}">
<xsl:with-param name="with-series">true</xsl:with-param>
</xsl:element> </xsl:template>

<xsl:template match="*[starts-with(local-name(), 'c') and @level != 'subseries' and @level != 'series']">
<xsl:element name="{name()}">
<xsl:with-param name="with-series" >false</xsl:with-param>

<xsl:template match="scopecontent">
 <xsl:param name="with-series"/>

   <xsl:when test="$with-series = 'true'">
     <p><xsl:value-of select="."/></p>
      <p><font size="-1" color="gray"/><xsl:value-of select="."/> </p>

<xsl:template match="@*|node()">
 <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>


Current Thread