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

Re: Refactoring parsing code with XSLT 2.0

Subject: Re: Refactoring parsing code with XSLT 2.0
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Fri, 13 May 2005 20:03:13 +1000
xslt and xmlns parsing
On 5/13/05, Micah Dubinko <micah@xxxxxxxxxxxx> wrote:
> Thanks,
>
> I've used tokenize, and I like it. But it seems to only work where you
> can throw away the delimiters.
>
> Ex.  "a b c" --> "a", "b", "c" (with the spaces gone)
>
> In this case, what I need is
>
> "3.04in" --> "3.04", "in"
>
> So I'd need a regex that hits in the right spot, but matches zero
> characters. I don't think lookaheads are in the spec. At least I haven't
> found them. Neither are subexpressions that I can tell.
>
> I still have a feeling that XSLT2 offers some elegant way to do this, at
> least more elegant than my current 11-line <xsl:choose> construction. Am
> I off-key?
>
> .micah


Using FXSL one would write (both in XSLT 1.0 and XSLT 2.0) something like
this:

<xsl:stylesheet version="2.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:f="http://fxsl.sf.net/"
 xmlns:myController="f:myController"
 xmlns:x="f:myTest"
 exclude-result-prefixes="f myController x"
 >
  <xsl:import href="../f/strSpan.xsl"/>
  <!-- To be applied on csstext.xml -->
  <xsl:output omit-xml-declaration="yes" indent="yes"/>

  <myController:myController/>

  <xsl:variable name="x:st" select="document('')/*"/>

  <xsl:template match="/">
    <xsl:call-template name="strSpan">
      <xsl:with-param name="pStr" select="string(/*)"/>
      <xsl:with-param name="pController"
                      select="$x:st/myController:*[1]"/>
      <xsl:with-param name="pContollerParam"
                      select="'0123456789.'"/>
      <xsl:with-param name="pElementName1" select="'value'"/>
      <xsl:with-param name="pElementName2" select="'unit'"/>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="myController:*" mode="f:FXSL">
    <xsl:param name="pChar"/>
    <xsl:param name="pParams"/>

    <xsl:if test="contains($pParams, $pChar)">1</xsl:if>
  </xsl:template>
</xsl:stylesheet>

When this transformation is applied on the following source xml document:

<csstext>5.5in</csstext>

the result is:

<value>5.5</value>
<unit>in</unit>

I haven't re-writen the "strSpan" template as an xsl:function simply
because I need to decide on a clear convention how to represents the
results of a function, which returns more than one sequence.

Cheers,
Dimitre Novatchev

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.