Re: Apply-templates for getting around my XML doc?

Subject: Re: Apply-templates for getting around my XML doc?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 11 Oct 2000 20:21:31 +0100
Hi Edmund,

At 10:33 AM 10/11/00 -0400, you wrote:
OK. If I wanted to process specific elements only, and no others, in the order listed in the stylesheet,
would the following XSLT be a correct way to navigate around?
<xsl:stylesheet etc.>
<xsl:template match='/'>
<xsl:apply-templates select="/L/0/iii"/> <!-- does this pass the ball directly to the template listed below?-->
</xsl:template>


<xsl:template match="/L/8/iii">
<!--do something-->
<xsl:apply-templates select="/X/4/vii"/> <!--and then does this go to the next template?-->
</xsl:template>

...Leaving aside that your element names couldn't actually be '0', '1', but would have to be 'A0' 'A1' etc. -- element names can't start with numerals ...


/L/8/iii would only match if your document element were L ... which it can't be, since you stipulate it's a sibling of M, X etc. (and well-formed documents can only have one document element). This is because the XPath location path starting with / navigates down from the root, which is above the document element.

So I'm surprised that these templates are matching at all.
Hopefully this can eliminate [this style of navigating] as a potential error. I don't understand how the processor thinks, and I had some problems with templates being ignored, but a wise man recommended this style as a [simple-enough-for-even-me-to-understand] potential solution. Have I missed even that boat?

Well, it's not that bad. It's really a case of fathoming the subtleties of XPath.


Try it again with examples like

<xsl:template match="X/8/iii">
  <xsl:apply-templates select="//L/4/ii"/>
</xsl:template>

and such like (note the positions of the slashes). Performance on this will be poor (that select expression is going to traverse the entire document looking for nodes), but it should work.

There are undoubtedly other ways to approach this problem, but my head is hurting after a day of teaching....

Good luck,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================


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



Current Thread