[xsl] AW: [Maybe Spam] Re: [xsl] Problem with a for-each in xsl:variable

Subject: [xsl] AW: [Maybe Spam] Re: [xsl] Problem with a for-each in xsl:variable
From: "Huditsch Roman" <Roman.Huditsch@xxxxxxxxxxxxx>
Date: Tue, 19 Oct 2004 17:31:51 +0200
Hi jeni,

Well, i am not quite sure, if your solution fits...

>  - 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
Yes, that's true. But I don't want the jur_block elements to get numbered.
They should stay as they are.

I just want to add new <nummer> elements (with the splitted number values for
the jur_block within range) under <stichwort>.

> 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.)
Yes, sorry. Was a typo in my mail...


Wbr,
Roman

-----Urspr|ngliche Nachricht-----
Von: Jeni Tennison [mailto:jeni@xxxxxxxxxxxxxxxx]
Gesendet: Dienstag, 19. Oktober 2004 17:23
An: Huditsch Roman
Cc: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Betreff: [Maybe Spam] Re: [xsl] Problem with a for-each in xsl:variable

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/



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