RE: [xsl] Problem relocating nodes and then applying templates

Subject: RE: [xsl] Problem relocating nodes and then applying templates
From: Ryan Graham <Ryan.Graham@xxxxxxxxxxxxx>
Date: Tue, 16 Sep 2003 16:01:16 -0700
This worked beautifully.

Thanks Tom,

-----Original Message-----
From: Passin, Tom [mailto:tpassin@xxxxxxxxxxxx] 
Sent: Tuesday, September 16, 2003 11:37 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Problem relocating nodes and then applying templates

[Ryan Graham]

> I currently have the following type of reference scattered 
> throughout an XML
> document (used as place-holders):
> <figureAnchor figures="c01-fig-xxxx"/>   ["xxxx" is some number]
> all of which reference a node structure at the end of the xml file:
> <figureGroup>
>     <figure id="c01-fig-0001">
>         <graphic xlink:href="file://images/someimage1.jpg" />
>         <caption>
>             <p>Figure caption 1</p>
>         </caption>
>     </figure>
>     <figure id="c01-fig-0002">
>         <graphic xlink:href="file://images/someimage2.jpg" />
>         <caption>
>             <p>Figure caption 2</p>
>         </caption>
>     </figure>
>     ...
> </figureGroup>
> When I come upon a <figureAnchor> tag during the transform to an FO
document, is there anyway to grab the proper node from the end of the
> document, insert it at the <figureAnchor> location, and then 
> apply-templates
> to format the elements?? 

Of course, it depends on how you "come across" the element (it is an
element, not a "tag" - xslt does not see start and end tags at all, only
nodes in a tree).  If the current node actually is a figureAnchor, then
this should do the job -

<xsl:variable name='figure-to-get' select='@figures'/>
<xsl:apply-templates select='/figureGroup/figure[@id=$figure-to-get]'/>

I have used a variable to make it clear what is going on and to prevent
any confusion about which node will be evaluated within the square
brackets. You do not always need to use such a variable, but it can be
useful for clarity.

This will cause the template for a "figure" element to transform the
figure element.  I presume that is what you have in mind.  The FO part
is up to you and the template.


Tom P

 XSL-List info and archive:

 XSL-List info and archive:

Current Thread