Re: [xsl] Counting the number of elements within and outputting a variable holding analyze-string results wrapped by elements in a for-each

Subject: Re: [xsl] Counting the number of elements within and outputting a variable holding analyze-string results wrapped by elements in a for-each
From: Michael Müller-Hillebrand <mmh@xxxxxxxxxxxxx>
Date: Mon, 30 Nov 2009 14:47:18 +0100
Alex,

Am 30.11.2009 um 14:35 schrieb Alex Muir:

> I'm interested in counting the number of elements in the variable
> $varAnalyzeStr holding analyze-string results wrapped by elements and
> then output the elements within the $varAnalyzeStr in a for-each.
>
> I've been able to count the number accurately however not output the
> variable varAnalyzeStr as a series of section elements. Currently I'm
> looping 15 times in the for each but no outputting any content.
>
> What am I doing wrong and is there a better way to do this?
>
>
>
> <xsl:variable name="varAnalyzeStr" as="node()*">
>         <xsl:analyze-string select="parent::node()/content/text()"
>           regex="Y(\d+)Y">
>           <xsl:matching-substring>
>
>             <xsl:element name="section">
>               <xsl:attribute name="href" select="regex-group(1)"/>
>             </xsl:element>
>
>           </xsl:matching-substring>
>         </xsl:analyze-string>
>  </xsl:variable>

this variable contains something like

<section href="123" />
<section href="456" />
<section href="789" />

i.e. empty elements, no text content. Your XSL tries to get "." from each
element, which is empty. Instead of xsl:value-of you should use xsl:copy-of.
And please give xsl:element a name.

>       <xsl:choose>
>         <xsl:when test="not(empty($varAnalyzeStr))">
>         <xsl:element name="">
>              <xsl:attribute name="Count" select="count($varAnalyzeStr)"/>
>              <xsl:for-each select="$varAnalyzeStr">
>                 <xsl:value-of select="."/>
>              </xsl:for-each>
>         </xsl:element>
>         </xsl:when>
>       </xsl:choose>

- Michael M|ller-Hillebrand

--
_______________________________________________________________
Michael M|ller-Hillebrand: Dokumentations-Technologie
Adobe Certified Expert, FrameMaker
Lvsungen und Training, FrameScript, XML/XSL, Unicode
Blog: http://cap-studio.de/ - Tel. +49 (9131) 28747

Current Thread