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">

<c01
level="series"><did><unittitle><unitdate></unitdate></unittitle><physdesc></physdesc></did>
<arrangement.</arrangement><scopecontent><p></p></scopecontent>

<c02
level="subseries"><did><unittitle><unitdate></unitdate></unittitle><physdesc></physdesc></did>
<arrangement.</arrangement><scopecontent><p></p></scopecontent>

<c03
level="file"><did><unittitle><unitdate></unitdate></unittitle><physdesc></physdesc></did>
<arrangement.</arrangement><scopecontent><p></p></scopecontent></c03>

<c03><did><unittitle><unitdate></unitdate></unittitle><physdesc></physdesc></did>
<arrangement.</arrangement><scopecontent><p></p></scopecontent></c03></c02></c01></dsc>

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,
lynn

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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

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


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


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

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

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

</xsl:stylesheet>

Current Thread