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

Re: Conditional text using attributes -- saxon:evaluat

Subject: Re: Conditional text using attributes -- saxon:evaluate?
From: "Steve Muench" <Steve.Muench@xxxxxxxxxx>
Date: Fri, 29 Dec 2000 09:19:56 -0800
first conditional emphasis
| Your augmented identity transformation is just what I had in mind --
| conditional inclusion based only on attribute names/values.
| 
| To further parameterize it, would it be possible to also specify an
| attribute name as a parameter along with the value
|
| For example, it would be very nice to be able to do something like:
| 
|   saxon test.xml beth.xsl attribute='os' value='PC'

This should do it:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:param name="attribute">os</xsl:param>
  <xsl:param name="value">Mac</xsl:param>
  <xsl:template match="node()|@*">
    <xsl:choose>
      <!-- 
       | If current node is an element having an attribute whose
       | local name (i.e. disregarding namespace prefix) matches
       | $attribute and whose value is not equals to $value, do nothing.
       +-->
      <xsl:when test="self::*[@*[local-name()=$attribute and . !=$value]]"/>
      <!-- 
       | Otherwise, copy it and process it's attributes/child nodes
       +-->
      <xsl:otherwise>
        <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

This may be less well-performing that the previous one
with a hard-coded attribute name, but is more generic...

If I alter my source to use the 'role' attribute like this:

<?xml version="1.0"?>
<article>
  <articleinfo>
    <title role="PC">Starting the timer using Microsoft Windows</title>
    <title role="Mac">Starting the timer using MacOS</title>
  </articleinfo>
  <para>
    Press the <emphasis role="PC">Left</emphasis> mouse button to start 
    the timer. You can use the <emphasis role="Mac">Finder</emphasis>
    <emphasis role="PC">Start Button</emphasis> to launch a new program.
  </para>
</article>

Then I can now do:

$ saxon test3.xml cond2.xsl attribute=role value=PC

<?xml version="1.0" encoding="utf-8"?>
<article>
    <articleinfo>
      <title role="PC">Starting the timer using Microsoft Windows</title>

    </articleinfo>
    <para>
      Press the <emphasis role="PC">Left</emphasis> mouse button to start
      the timer. You can use the
      <emphasis role="PC">Start Button</emphasis> to launch a new program.
    </para>
  </article>

______________________________________________________________
Steve Muench, Lead XML Evangelist & Consulting Product Manager
BC4J & XSQL Servlet Development Teams, Oracle Rep to XSL WG
Author "Building Oracle XML Applications", O'Reilly
http://www.oreilly.com/catalog/orxmlapp/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.