xsl-list
[Top] [All Lists]

Re: [xsl] extracting data from an element

2009-02-03 07:31:54
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/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>