Subject: Re: [xsl] Problem with a for-each in xsl:variable From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Tue, 19 Oct 2004 16:23:26 +0100 |
Hi Huditsch, > I need to split up value ranges like "14-24" with the help of an > xslt stylesheet. The difficulty doing this task is, that these > ranges can also look like "13 13a 13b 14 15 15a 16..." There's no need to use a temporary tree here. I'm going to assume that: - the <jur_block> elements appear in order - you're dealing with large numbers of <jur_block> elements - if the range is 14-24, you want to include 24, but not 24a etc. - the ranges that you're interested in aren't necessarily contiguous and might overlap First, create a template for the <jur_block> elements with a parameter -- $end -- that outputs a <nummer> element for the <jur_block>, and then moves on to the next (sibling) <jur_block> element if $end is not equal to the child <zaehlung> element: <xsl:template match="ln:jur_block"> <xsl:param name="end" /> <nummer><xsl:value-of select="ln:zaehlung" /></nummer> <xsl:if test="$end != ln:zaehlung"> <xsl:apply-templates select="following-sibling::ln:jur_block[1]"> <xsl:with-param name="end" select="$end" /> </xsl:apply-templates> </xsl:if> </xsl:template> Note that you need to associate the namespace 'http://myNamespace/schema/norm' with a prefix within your stylesheet in order to refer to elements in that namespace. In the above, I've assumed that you've associated it with the prefix 'ln'. (In your stylesheet, you'd associated 'ln' with the namespace 'http://www.lexisnexis.at/schema/norm'. Either this was a typo, or it might be the reason you weren't getting the output you were expecting -- the namespaces you use in the stylesheet and the source have to match.) The above template will step through the <jur_block> elements one by one, outputting <nummer> elements, until it gets to the <jur_block> element whose <zaehlung> matches the value of the $end parameter. To start the process off, you have to apply templates to the <jur_block> element that corresponds to the start of the range. To do this, I'd define a key that indexes each <jur_block> element by its <zaehlung> child: <xsl:key name="blocks" match="ln:jur_block" use="ln:zaehlung" /> Then, in the template that matches the <stichwort> element, you can do: <xsl:template match="stichwort"> ... <xsl:apply-templates select="key('blocks', substring-before(nummer, '-'))"> <xsl:with-param name="end" select="substring-after(nummer, '-')" /> </xsl:apply-templates> ... </xsl:template> Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] Problem with a for-each in xs, Huditsch Roman | Thread | [xsl] Stripping or converting HTML , Aaron Johnson |
Re: [xsl] Stripping or converting H, Bruce D'Arcus | Date | Re: [xsl] Stripping or converting H, David Carlisle |
Month |