xsl-list
[Top] [All Lists]

How to get preceding-siblings that appear before a certain text

2005-09-29 04:19:38
Hi!

I have this source file:

<test>
<p>Aaron<xref>test1</xref>
<xref>test2</xref> Abraham<xref>test3</xref> Adam and
Eve<xref>test4</xref> Adam<xref>test5</xref>
</p>
</test>

and a xsl file like these:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns:fn="http://www.w3.org/2005/02/xpath-functions";
xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes";>
<xsl:character-map name="map">
<xsl:output-character character="&amp;"
string="&amp;"/>
</xsl:character-map>
<xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes"
use-character-maps="map"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{name(.)}">
<xsl:apply-templates/>
</xsl:element>
</xsl:template>

<xsl:template match="p">
<xsl:for-each select="text()">
<xsl:element name="indexterm">
<xsl:attribute name="sort"><xsl:value-of
select="."/></xsl:attribute>
<xsl:attribute name="type">name</xsl:attribute>
<xsl:element name="headword"><xsl:value-of
select="."/></xsl:element>
<xsl:element name="indextermbody">
<xsl:element name="p">
<xsl:apply-templates
select="following-sibling::xref"/>
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>

And want an output like this:

<test>
<indexterm sort="Aaron" type="name">
<headword>Aaron</headword>
<indextermbody>
<p><xref>test1</xref><xref>test2</xref></p>
</indextermbody>
</indexterm>
<indexterm sort=" Abraham" type="name">
<headword> Abraham</headword>
<indextermbody>
<p><xref>test3</xref></p>
</indextermbody>
</indexterm>
<indexterm sort=" Adam and Eve" type="name">
<headword> Adam and Eve</headword>
<indextermbody>
<p><xref>test4</xref></p>
</indextermbody>
</indexterm>
<indexterm sort=" Adam" type="name">
<headword> Adam</headword>
<indextermbody>
<p><xref>test5</xref></p>
</indextermbody>
</indexterm>
</test>

But what i'm getting, because of the
following-sibling::xref, all of the xref and not the
xref that that appear before the next text() node. Is
there a way to achieve this?

-- UlyLee


                
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.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>
--~--



<Prev in Thread] Current Thread [Next in Thread>