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

Re: Possible to use attribute value in pattern ??

Subject: Re: Possible to use attribute value in pattern ??
From: "Pete Johnston" <P.Johnston@xxxxxxxxxxxxxxxxxx>
Date: Fri, 16 Jul 1999 10:08:48 GMT
xsl apply templates attribute value
[Caleb Drake]
> Suppose the source document has:
> <book title="All About Foo" author="Dr. Quux"/>
> and I want to place the title in one part of the result tree and the author
> in another.  To do so, I might have
> <xsl:apply-templates select="book[@title]"/>
> in one place, and
> <xsl:apply-templates select="book[@author]"/>
> in the other.  The problem is that both apply-templates "calls" match the
> same
> source element so only one of them gets generated.  In addition, the
> template
> rule triggered by these two apply-templates tags cannot distinguish which
> apply-templates "call" triggered the rule, so it doesn't know which
> attribute to style

I'm not sure I have understood your problem correctly, but my 
interpretation is that your two apply-templates elements here are 
selecting (respectively) the book element which has a title attribute 
and the book element which has an author attribute - which in 
your case turn out to be the same element, and so the same 
(match="book"?) template is instantiated. 

But it sounds like what you want is to select _separately_ the author 
attribute of the book element and the title attribute of the book 
element (rather than the book element itself). This requires a 
different pair of patterns:

<xsl:apply-templates select="book/@title"/>
<xsl:apply-templates select="book/@author"/>

I think this is the point David Carlisle was illustrating with his 
three examples yesterday.

For example with this document

<?xml version="1.0" ?>
<list>
<book title="Neuromancer" author="William Gibson">some content about
Neuromancer</book>
<book title="Snow Crash" author="Neal Stephenson">some content about 
Snow Crash</book>
</list>

the stylesheet

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
    result-ns="">

<xsl:template match="list">

<xsl:apply-templates select="book[@title]"/>
<xsl:apply-templates select="book[@author]"/>

</xsl:template>

<xsl:template match="@*">
<xsl:value-of select="."/>
</xsl:template>

</xsl:stylesheet>

produces a rather different result from

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0"
    result-ns="">

<xsl:template match="list">

<xsl:apply-templates select="book/@title"/>
<xsl:apply-templates select="book/@author"/>

</xsl:template>

<xsl:template match="@*">
<xsl:value-of select="."/>
</xsl:template>

</xsl:stylesheet>

Many apologies if I'm missing the point you are making!

Pete Johnston
University of Glasgow


 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.