[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] extracting data from an element


Subject: Re: [xsl] extracting data from an element
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Tue, 03 Feb 2009 13:31:19 +0100

Martin Honnen wrote:
Mike Stroud wrote:

Today I have a different problem. How do I extract data from an
element?

If you use XSLT 2.0 then look into xsl:analyze-string http://www.w3.org/TR/xslt20/#analyze-string

Here is an example:


<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0">

<xsl:output method="xml" indent="yes"/>

  <xsl:template match="DIMENSIONS">
    <xsl:copy>
      <xsl:apply-templates/>
    </xsl:copy>
  </xsl:template>

<xsl:template match="DIMENTION">
<xsl:copy>
<xsl:analyze-string select="." regex="\s+T=(\d+)\s+(\d+)\s+x\s+(\d+)">
<xsl:matching-substring>
<Length>
<xsl:value-of select="regex-group(1)"/>
</Length>
<Width>
<xsl:value-of select="regex-group(2)"/>
</Width>
<Mass>
<xsl:value-of select="regex-group(3)"/>
</Mass>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:copy>
</xsl:template>


</xsl:stylesheet>

Note that you use the odd spelling "DIMENTION" in your XML input sample so the match attribute uses that spelling too.



--

	Martin Honnen
	http://JavaScript.FAQTs.com/


Current Thread
Keywords