[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] X-Path expressions confusions


Subject: Re: [xsl] X-Path expressions confusions
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 30 Jul 2002 09:31:11 +0100

Hi Ashu,

> 1. I have read this at
> http://www.w3.org/TR/xslt#section-Applying-Template-Rules
>
> *In the absence of a select attribute, the xsl:apply-templates 
> instruction processes all of the children of the current node, 
> including text nodes.*
>    Does that mean if we use <xsl:apply-templates select="*"/> 
> instead of <xsl:apply-templates/> both are same except the one 
> will process all child nodes and the other will process all but 
> text child nodes.

Sort of. The XPath expression "*" selects all the child *elements* of
the context node, whereas the XPath expression "node()" selects all
the child *nodes* of the context node: elements, text nodes, comments
and processing instructions.

So:

  <xsl:apply-templates />

is equivalent to:

  <xsl:apply-templates select="node()" />

> 2.
> And one thing about overriding template rules.
>   <xsl:template match="node"/>
> Does that mean it will do nothing to node and process the child 
> nodes of node or It means it will not process any node which are 
> inside <node> and </node> like
> <node>
>    <node1>......</node1>
>     <node2>......</node2>
> </node>

The latter. The template says "when you find a node element, do
nothing". If you wanted it to say "when you find a node element,
process its children" then you'd need:

<xsl:template match="node">
  <xsl:apply-templates />
</xsl:template>

> 3.
> If we have
> <xsl:template match
> ="text()[preceding-sibling::node()[1][self::input][not(normalize-space())]]
> then we read it from left to right so if this has to be read it 
> reads
> Template matches text() node then check the first perceding 
> sibling of that node whether it is input or not and white spaces 
> in text node should be preserved. right?

Roughly. This template matches text nodes whose immediately preceding
sibling is an input element that doesn't have any non-whitespace
textual content. For example, it would match the text in:

  <input />text

or:

  <input>
  </input>text
  
but not in:

  <foo />text

or:

  <input>
    foo
  </input>text

> 4.
>   Some times we use "." dot and sometimes "*" astric
>   Are they not same used for all elements or they are different as 
> in select we use "*" and in count we use
> "." like count(.| some key).

They are different. "." is short for "self::node()" whereas "*" is
short for "child::*". So "." will get you the node that you're on at
the moment (the context node), whereas "*" will get you the child
elements of the node that you're on at the moment.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


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



Current Thread
Keywords