[xsl] Assigning keywords according to their number

Subject: [xsl] Assigning keywords according to their number
From: "Huditsch Roman" <Roman.Huditsch@xxxxxxxxxxxxx>
Date: Thu, 21 Oct 2004 16:39:45 +0200
Hi,

I am really sorry for bothering you with another problem of mine, but I wasn't
abler or come to a solution myself so far.

I have the following source document:

...
<stichworte>
	<stichwort>
		<term>Abgerissenes Land</term>
		<nummer>412ff</nummer>
	</stichwort>
	<stichwort>
		<term>Abhandlung der Erbschaft</term>
		<nummer>797</nummer>
		<nummer>798a</nummer>
		<nummer>823</nummer>
	</stichwort>
	<stichwort>
		<term>Abschlagszahlung</term>
		<nummer>1415f</nummer>
		<nummer>1428</nummer>
	</stichwort>
</stichworte>
...
<jur_block id="N12847">
	<zaehlung zaehlungsart="Paragraf">189</zaehlung>
	<absatz>Derjenige, den das Gericht</absatz>
</jur_block>
<jur_block id="N12862">
	<zaehlung zaehlungsart="Paragraf">190</zaehlung>
	<absatz>Eine besonders geeignete</absatz>
</jur_block>
...

I need to assign those <stichwort> elements to their apropriate jur_block
element accoring to their paragraph number (within <zaehlung
zaehlungsart="Paragraf">

So I need to check:

* If there is a <stichwort> with a <nummer> matching the value in <zaehlung>
=> put that keyword in this jur_block

* If there is a <stichwort> with a <nummer> containing an "f", this keyword
needs to be assigned to the paragraph with substring-before(nummer,
'f')=zaehlung AND its next following-sibling.

* If there is a <stichwort> with a <nummer> containing "ff", this keyword
needs to be assigned to the paragraph with substring-before(nummer,
'f')=zaehlung AND all of its following-siblings.



Here is the stylesheet I tried....


<?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
common" xmlns:common="http://exslt.org/common";>
	<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:jur_block[not(@v_ref) or
@v_marker='dazu']/ln:zaehlung[@zaehlungsart='Paragraf']">
		<xsl:variable name="val" select="."/>
		<xsl:variable name="pos" select="position() - 1"/>
		<xsl:variable name="sib"
select="../preceding-sibling::ln:jur_block[not(@v_ref) or
@v_marker='dazu'][$pos]/ln:zaehlung[@zaehlungsart='Paragraf']"/>
		<xsl:copy-of select="."/>
		<!-- Each keyword gets assigned to the current block, when its <number>
element matches the content of the <zaehlung> element-->
		<xsl:apply-templates select="//ln:stichwort[ln:nummer=$val]"/>
		<!-- Each keyword gets assigned to the current block, when its <number>
element contains an "f" but the substring-before "f" matches the content of
the <zaehlung> element-->
		<xsl:apply-templates select="//ln:stichwort[ln:nummer=concat($val, 'f')]"/>
		<!-- Each keyword gets assigned to the current block, when its <number>
element contains an "ff" but the substring-before "ff" matches the content of
the <zaehlung> element-->
		<xsl:apply-templates select="//ln:stichwort[ln:nummer=concat($val,
'ff')]"/>

		<xsl:apply-templates select="//ln:stichwort[substring-before(ln:nummer,
'ff')=../preceding-sibling::ln:jur_block/ln:zaehlung"/>
		<!-- Assign Keywords for <nummer>XXXf</nummer> entries -->
		<xsl:apply-templates select="//ln:stichwort[ln:nummer=concat($sib, 'f')]"/>
	</xsl:template>
	<!-- Keywords for clauses are assigned -->
	<xsl:template match="ln:jur_block[parent::ln:jur_block[not(@v_ref) or
@v_marker='dazu']]/ln:zaehlung[@zaehlungsart='Absatz']">
		<xsl:variable name="val" select="."/>
		<xsl:variable name="para"
select="../../ln:zaehlung[@zaehlungsart='Paragraf']"/>
		<xsl:copy-of select="."/>
		<xsl:apply-templates select="//ln:stichwort[ln:nummer=concat($para,'(',
$val, ')')]"/>
	</xsl:template>
	<xsl:template match="ln:stichwort">
		<xsl:element name="stichwort"
namespace="http://www.lexisnexis.at/schema/norm";>
			<xsl:value-of select="ln:term"/>
		</xsl:element>
	</xsl:template>
	<!-- The following elements should me omitted in the output -->
	<xsl:template match="ln:stichworte"/>
</xsl:stylesheet>


Can you help me?
Thanl you very very much in advance.

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
**********************************************************************

Current Thread