xsl-list
[Top] [All Lists]

Re: Strict sequential identity rule?

2005-09-21 14:01:51
Replying to all who were interested to have a look at this.

No, the provided code *is not* an identity transform.

It is very close to an identity transform though...


I found this example interesting, because it shows that

   node()

does not match the document node "/" -- *as a match pattern*.

The transformation will start by applying the built-in template rule:

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


In case the document node has more than one child -- as in the example
provided by Joris, this will apply templates separately
(independently, parallelly) to these children.

Only then the template in the code will be applied (to all these
children) and the result will be producing N different copies (one for
each of the N different children of the document node) of

   descendent-or-self::node() |  following-sibling::node()

for each child of the document node.

So, to be more exact, in case N = 1 the provided code produces
identical results to those of a real identity transform.


For me the interesting part was to be reminded that

    node()

does not match "/"

if used as a match pattern.


Another interesting question is:

How many different templates get selected and applied in the case when
our code is the wellknown identity rule:

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>


Now, we can easily say that the answer is: two templates.

As a consequence, I think that it would be very helpful to have in
XSLT facilities, which provide warning diagnostics whenever a built-in
template rule is invoked, or to turn off built-in template rules at
all. There is something like this in XSelerator.

Probably vendors of XSLT  processors could provide such facilities?

Cheers,
Dimitre Novatchev.




On 9/21/05, Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:
OK, Dimitre, I give up. I know you've got a rabbit up your sleeve, and I
can't ferret it out.

I was thinking the catch might be that a node produced by copying can never
be "identical" to the original, but I can't imagine that's what you had in
mind.

Michael Kay
http://www.saxonica.com/

-----Original Message-----
From: Dimitre Novatchev [mailto:dnovatchev(_at_)gmail(_dot_)com]
Sent: 21 September 2005 13:48
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Strict sequential identity rule?

Hi,
I think that trying to answer the following question can be
interesting and
useful for the members of our community.

 Is the following statement true or false:

"The transformation below is an identity transformation":

 <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
      <xsl:output omit-xml-declaration="yes"/>
      <xsl:template match="@* | node()">
              <xsl:copy>
                      <xsl:apply-templates select="@*"/>
                      <xsl:apply-templates select="node()[1]"/>
              </xsl:copy>
              <xsl:apply-templates
select="following-sibling::node()[1]"/>
      </xsl:template>
</xsl:stylesheet>


--
Cheers,
Dimitre Novatchev
---------------------------------------
Getting caught is the mother of invention.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--






--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--
Cheers,
Dimitre Novatchev
---------------------------------------
Getting caught is the mother of invention.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--