[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: extracting data from an element

Subject: Re: extracting data from an element
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Tue, 03 Feb 2009 13:31:19 +0100
Re:  extracting data from an element
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.