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

Re: [xsl] Stumped on XPath


Subject: Re: [xsl] Stumped on XPath
From: Spencer Tickner <spencertickner@xxxxxxxxx>
Date: Mon, 13 Feb 2006 13:24:01 -0800

Hi Wendell,

Thanks for the write back, here's the xslt code..
<xsl:stylesheet version="1.0"
             xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:key name="r" match="refnote" use="@id"/>

<xsl:template match="doc">
<html>
<head/>
<body>
 <xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match="sentence">
 <p><xsl:apply-templates/></p>
</xsl:template>
<xsl:template match="clause">
 <p class="clause"><xsl:apply-templates/></p>
</xsl:template>
<xsl:template match="strong">
<strong><xsl:apply-templates/></strong>
</xsl:template>
<xsl:template match="appendix"/>
<xsl:template match="id">
<xsl:for-each select="key('r',@ref)">
 <xsl:text> (see Appendix </xsl:text>
 <xsl:number format="A"/>
 <xsl:text>) </xsl:text>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

I'll give a shot at trying to switch his code to count the appendix instead.

thanks,

Spencer

On 2/13/06, Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> wrote:
> Hi Spenser,
>
> If you posted your original XSLT which David fixed, that would help,
> but I think I remember it well enough -- David's suggestion should
> work cleanly as long as you say
>
> <xsl:number from="appendix"/>
>
> instead of the <xsl:number/> he guessed at.
>
> The principle he elucidated, namely that you traverse to the
> referenced node and do the operation there, still applies.
> <xsl:number/> (in some configuration) spares you all the work of
> counting things using explicit XPath. The only tricky part is getting
> the xsl:number set up to give what you want. In this case, unless you
> say you want to count the appendix elements, it uses the default,
> which is counting the refnote elements themselves, in their local
> context (i.e. each one inside its parent). This gives you "1" (i.e.
> "A") for refnotes 1, 2, and 4, which are each the first refnotes in
> their parents. (refnote 3 will get you "B"). By switching this to
> count the appendixes you should get "A" for refnote 1, "B" for
> refnotes 2 and 3, and "C" for 4.
>
> Cheers,
> Wendell
>
> At 04:03 PM 2/13/2006, you wrote:
> >Hi Wendell and David,
> >
> >Sorry I was out of town on a course. I do agree that the solution that
> >David suggested is cleaner, however it only works with the original
> >xml. Sorry if the second example was obscure, perhaps this demostrates
> >it better:
> >
> >XML
> >
> ><?xml version="1.0"?>
> ><doc>
> >  <manual>
> >  <sentence>This is a sentence with a reference<id ref="1"/> as an
> >inline element</sentence>
> >     <clause>This is a clause with inline elements <strong>
> >and</strong> a reference <id ref="4"/></clause>
> ></manual>
> ><appendix>
> >  <refnote id="1">This is the first reference</refnote>
> >  </appendix>
> >  <appendix>
> >  <refnote id="2">This is the second reference</refnote>
> ><refnote id="3">This is the third reference</refnote>
> ></appendix>
> ><appendix>
> >         <refnote id="4">This is the third reference</refnote>
> >  </appendix>
> ></doc>
> >
> >Should produce:
> >
> ><html><head><META http-equiv="Content-Type"
content="text/html"></head><body>
> >  <p>This is a sentence with a reference (see Appendix A)  as an
> >inline element</p>
> >     <p class="clause">This is a clause with inline elements <strong>
> >and</strong> a reference  (see Appendix C) </p>
> ></body></html>
> >
> >But instead produces:
> >
> ><html><head><META http-equiv="Content-Type"
content="text/html"></head><body>
> >  <p>This is a sentence with a reference (see Appendix A)  as an
> >inline element</p>
> >     <p class="clause">This is a clause with inline elements <strong>
> >and</strong> a reference  (see Appendix A) </p>
> ></body></html>
> >
> >I'm sure it's something small I'm missing on my end. I do agree that
> >this would be a much better solution, so any thoughts would be
> >appreciated
>
>
> ======================================================================
> 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
> ======================================================================


Current Thread
Keywords