[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: Michael Smith <smith@xxxxxxxxxxx>
Date: 28 Dec 2000 23:23:18 -0800
saxon conditional example
Steve, 

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 -- if not using
"standard" XSLT, maybe instead with an application-specific extension
function like Saxon's saxon:evaluate?

For example, it would be very nice to be able to do something like:

  saxon test.xml beth.xsl attribute='os' value='PC'

Is that possible?  It would be great not to need to explicitly specify
the attribute name within the stylesheet/transform itself.

   --Mike Smith

(I put one more comment after the following quoted stuff.)


Michael Smith <smith@xxxxxxxxxxx> writes:

> | So instead of importing the DocBook templates, might it be possible
> | instead to write a straight XML to XML "conditional inclusion"
> | transform that will work with *any* well-formed XML document instance?
> | 
> | What I mean specifically is a transform that:
> | 
> |   * conditionally includes elements based simply on attribute
> |     names/values, without regard at all for the actual element names
> | 
> |   * is a "standalone" transform that doesn't rely on importing other
> |     stylesheets that contain templates matching the element names
> | 
> | Is that possible? How could it be expressed in XSLT?

Steve Muench <Steve.Muench@xxxxxxxxxx> writes:

> The following stylesheet augments the identity transformation with a
> template that suppresses copying to the result any element which
> *HAS* an "os" attribute whose value is *different* from the current
> top-level os parameter value.
> 
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
> 
>   <xsl:param name="os">Mac</xsl:param>
> 
>   <!-- Identity Transformation -->
>   <xsl:template match="node()|@*">
>     <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
>   </xsl:template>
> 
>   <!-- 
>    | If element HAS an os attribute and its value is NOT
>    | what we're looking for, then squelch it
>    +-->
>   <xsl:template match="*[@os and @os!=$os]"/>
> 
> </xsl:stylesheet>
> 
> [...] This assumes that if an element has os="Mac" -- and the
> current value of the $os param = "PC" -- that you want that element
> AND ALL OF ITS CONTENT to be squelched along with it.

I think squelching all of the element's child nodes is exactly what
most document authors would want -- that is, the capability to
recursively exclude whole sections/chunks of documents, along with
excluding simple inline content.

-- 
Michael Smith          mailto:smith@xxxxxxxxxxx
XML-Doc                http://www.xml-doc.org/



 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.