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

Subject: Re: [xsl] Problem with a for-each in xsl:variable
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Tue, 19 Oct 2004 17:07:17 +0100
Hi Roman,

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

Sure. But the numbers that you want to add under <stichwort> need to
come from the <jur_block> elements, right? The way I was suggesting
you achieve this is to apply templates to the <jur_block> elements in
order to create the <nummer> elements. If you apply templates to those
<jur_block> elements within a <stichwort> element that you've created,
then the <nummer> elements you create will appear within that
<stichwort> element. Use a mode if you need to apply templates to the
<jur_block> elements in other places in your stylesheet as well. For
example, try:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:ln="http://myNamespace/schema/norm";
                exclude-result-prefixes="ln">

<xsl:template match="node()|@*">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()" />
  </xsl:copy>
</xsl:template>
                
<xsl:key name="blocks" match="ln:jur_block" use="ln:zaehlung" />

<xsl:template match="stichwort">
  <stichwort>
    <xsl:apply-templates select="term" />
    <xsl:apply-templates select="key('blocks',
                                     substring-before(nummer, '-'))"
                         mode="nummer">
      <xsl:with-param name="end"
                      select="substring-after(nummer, '-')" />
    </xsl:apply-templates>
  </stichwort>
</xsl:template>

<xsl:template match="ln:jur_block" mode="nummer">
  <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]"
                         mode="nummer">
      <xsl:with-param name="end" select="$end" />
    </xsl:apply-templates>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Current Thread