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

[xsl] Re: Move (ascend) an element


Subject: [xsl] Re: Move (ascend) an element
From: Naomi Gronson <naomi_gronson@xxxxxxxxx>
Date: Tue, 9 Nov 2004 13:27:45 -0800 (PST)

I used a modification of the provided example to try
and move indexterms from inside /figure/title to just
above the title, but I seem to be losing my figure
attributes like id and role (because of a shallow
copy?)--doing it this way also for some reason takes
another indexterm from earlier in the xml file and
puts it right before the one I want moved (this, I
have no clue about):

<xsl:template
match="figure[child::title[child::indexterm]]">
   <xsl:copy>
     <xsl:copy-of select="//indexterm"/>
     <xsl:apply-templates select="@*|node()"/>
   </xsl:copy>
</xsl:template>

<!-- remove old indexterm -->
<xsl:template
match="indexterm[parent::title[parent::figure]]"/>

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

=

<figure>
<indexterm>
<primary>Why is this here?</primary>
<secondary>It was inside a paragraph earlier in the
file</secondary>
</indexterm>
<indexterm>
<primary>Good XE</primary>
<secondary>Good XE</secondary>
</indexterm>
<title id="abc">This is a figure</title>
<mediaobject>
<imageobject>
<imagedata fileref="000088.jpg">
</imagedata>
</imageobject>
</mediaobject>
</figure>

Any ideas (how to allow Figure to keep it's attributes
while moving the indexterm within Figure/title to
above <title>--without grabbing indexterms from
earlier in the file)?  This thread is a few months
old...sorry about that. :-)  Thanks for the help.

Naomi


To:  xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
Subject:  RE: [xsl] Move (ascend) an element 
From:  Pieter Reint Siegers Kort
<pieter.siegers@xxxxxxxxxxx> 
Date:  Thu, 1 Jul 2004 09:46:24 -0500  

Hi Naomi,

Using an excellent example of G. Ken Holman, posted by
him a couple of days
ago, I modified it to the following:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">

<xsl:output indent="yes"/>

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

<xsl:template match="indexterm"/>

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

</xsl:stylesheet>

This produces (with your XML as input, I only added an
extra element
<secterm>):

<?xml version="1.0" encoding="UTF-16"?>
<figure>
<indexterm>
<primary>special figure</primary>
<secterm>xxx</secterm>
</indexterm>
<title>
        This is the figure caption text
        </title>
</figure>

Cheers,
<prs/>

-----Original Message-----
From: Naomi Gronson [mailto:naomi_gronson@xxxxxxxxx] 
Sent: Thursday, July 01, 2004 9:23 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Move (ascend) an element

I'm trying to move the <indexterm> up in the tree,
from:

<figure>
        <title>
                <indexterm>
                <primary>special figure</primary>
                </indexterm>
        This is the figure caption text
        </title>
</figure>

to

<figure>
        <indexterm>
        <primary>special figure</primary>
        </indexterm>
        <title>This is the figure caption text</title>
</figure>

I have code that does it part way, but won't handle
any <secondary> elements
that might also be contained within the <indexterm>:

<xsl:template
match="figure[descendant::title[descendant::indexterm]]">
<xsl:copy><indexterm><primary>
<xsl:value-of
select="descendant::indexterm"/></primary></indexterm>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<!-- remove old indexterm -->
<xsl:template
match="indexterm[ancestor::title[ancestor::figure]]">
</xsl:template>

Is there some kind of value of select that will grab
the <indexterm> and any
elements under it, instead of me recreating them in my
xsl?  Any ideas.
Thanks!

Naomi




 



		
__________________________________ 
Do you Yahoo!? 
Check out the new Yahoo! Front Page. 
www.yahoo.com 


Current Thread
Keywords
xml