[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Writing conditional statement based on attribute

Subject: Re: Writing conditional statement based on attribute
From: Kamal Bhatt <kbhatt@xxxxxxxxx>
Date: Wed, 07 Feb 2007 08:36:01 +1100
Re:  Writing conditional statement based on attribute
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.