RE: Possible to use attribute value in pattern ??

Subject: RE: Possible to use attribute value in pattern ??
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Fri, 16 Jul 1999 09:59:46 +0100
> Perhaps, we're wrong, but our understanding of the spec and 
> our experience with SAXON is that a particular source element can only be 
> matched once during the styling process.

No, it can be matched as often as you like.

  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.

Several points here:
- if you want to have one template for each attribute, you can:
<xsl:template match="book/@title">
<xsl:apply-templates select="book/@title">
<xsl:template match="book/@author">
<xsl:apply-templates select="book/@author">

- normally this isn't necessary. Instead of matching the attribute with a
why not just access its value using <xsl:value-of select="book/@title"/> ?

  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 guessing that this can be handled with a variable).

You could distinguish the calls using a parameter, or using modes. But in
this situation, you don't need to: think in terms of processing the
attributes as nodes, not the elements they belong to.

> Am I missing or misunderstanding something?
Yes! Hope the explanation helps.

Mike Kay

 XSL-List info and archive:

Current Thread