xsl-list
[Top] [All Lists]

XPath Problem - selecting the previos node

2004-10-25 02:00:20
Hi,

Although I looked into the archive I couldn't find an appropriate response to 
my question, which is quite simple...

I need to store the value of the first previous sibling, which doesn't start 
with "-" in a variable.

Heres my XML:

<?xml version="1.0" encoding="UTF-8"?>
<norm xmlns="http://www.lexisnexis.at/schema/norm"; id="abgb">
        <stichworte>
                <stichwort_alt>Abgerissenes Land 412(1)</stichwort_alt>
                <stichwort_alt>Abhandlung der Erbschaft 797</stichwort_alt>
                <stichwort_alt>Anerkennung der Vaterschaft 154</stichwort_alt>
                <stichwort_alt>-, Rechtswirksamerklärung 164</stichwort_alt>
                <stichwort_alt>-, Widerspruch 163d, 163e</stichwort_alt>
...


I need to replace leading "-" with the first word of the previous sibling not 
beginging with "-". 
So my desired output should look like

        ...
        <stichwort_alt>Anerkennung der Vaterschaft 154</stichwort_alt>
        <stichwort_alt> Anerkennung, Rechtswirksamerklärung 164</stichwort_alt>
        <stichwort_alt> Anerkennung, Widerspruch 163d, 163e</stichwort_alt>


I tried to achieve this with the following stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
xmlns:ln="http://www.lexisnexis.at/schema/norm"; exclude-result-prefixes="ln">
        <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
        <xsl:template match="node() | @*">
                <xsl:copy>
                        <xsl:apply-templates select="@* | node()"/>
                </xsl:copy>
        </xsl:template>
        <xsl:template match="ln:stichworte">
                <xsl:element name="stichworte" 
namespace="http://www.lexisnexis.at/schema/norm";>
                        <xsl:apply-templates select="ln:stichwort_alt"/>
                </xsl:element>
        </xsl:template>
        <xsl:template match="ln:stichwort_alt">
        
        <!-- I THINK HERE IS THE PROBLEM -->
                <xsl:variable name="sib" 
select="preceding-sibling::ln:stichwort_alt[not(starts-with(., '-'))]"/>
                <xsl:element name="stichwort" 
namespace="http://www.lexisnexis.at/schema/norm";>
                        <xsl:choose>
                                <!-- Replacing leading "-," -->
                                <xsl:when test="starts-with(., '-,')">
                                        <xsl:choose>
                                                <xsl:when 
test="contains(substring-before($sib, ' '), ',')">
                                                        <xsl:value-of 
select="substring-before($sib, ',')"/>
                                                        <xsl:text>,</xsl:text>
                                                        <xsl:value-of 
select="substring-after(., '-,')"/>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                        <xsl:value-of 
select="substring-before($sib, ' ')"/>
                                                        <xsl:text>,</xsl:text>
                                                        <xsl:value-of 
select="substring-after(., '-,')"/>
                                                </xsl:otherwise>
                                        </xsl:choose>
                                </xsl:when>
                                <xsl:otherwise>
                                        <xsl:value-of 
select="normalize-space(text())"/>
                                </xsl:otherwise>
                        </xsl:choose>
                </xsl:element>
        </xsl:template>
</xsl:stylesheet>


I am always getting the first node in return. I tried different things with 
position(), but it didn't work either...

Can you help me?
Thanks in advane.

Wbr,
Roman


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



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