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

RE: copy-of problem...

Subject: RE: copy-of problem...
From: Américo Albuquerque <melinor@xxxxxxx>
Date: Tue, 15 Jul 2003 15:17:55 +0100
xsl substring before
Hi

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> David.Pawson@xxxxxxxxxxx
> Sent: Monday, July 14, 2003 12:01 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE:  copy-of problem...
> 
> 
> Hi Jeni. 
> > As usual, the easiest recourse here is to use DOE (this is 
> what it's 
> > designed for):
> > 
> > <xsl:template match="description">
> >   <xsl:value-of select="." disable-output-escaping="yes" /> 
> > </xsl:template>
> 
> Well it works Jeni... but I would like to know just why.
> I've never had to use doe before.

If you don't want to use doe you could use these templates:

  <xsl:template match="description">
    <xsl:copy>
      <xsl:call-template name="parse"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template name="parse">
    <xsl:param name="str" select="."/>
    <xsl:choose>
      <xsl:when test="contains($str,'&lt;')">
        <xsl:variable name="tag"
select="substring-before(substring-after($str,'&lt;'),'&gt;')"/>
        <xsl:variable name="endTag">
          <xsl:choose>
            <xsl:when test="contains($tag,' ')">
              <xsl:value-of select="substring-before($tag,' ')"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="$tag"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:call-template name="parse">
          <xsl:with-param name="str"
select="substring-before($str,concat('&lt;',$tag,'&gt;'))"/>
        </xsl:call-template>
        <xsl:call-template name="parseTag">
          <xsl:with-param name="tag" select="$tag"/>
          <xsl:with-param name="endTag" select="normalize-space($endTag)"/>
          <xsl:with-param name="value"
select="substring-before(substring-after($str,concat('&lt;',$tag,'&gt;')),co
ncat('&lt;/',normalize-space($endTag),'&gt;'))"/>
        </xsl:call-template>
        <xsl:call-template name="parse">
          <xsl:with-param name="str"
select="substring-after($str,concat('&lt;/',normalize-space($endTag),'&gt;')
)"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$str"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="parseTag">
    <xsl:param name="tag" select="''"/>
    <xsl:param name="endTag" select="''"/>
    <xsl:param name="value" select="''"/>
    <xsl:element name="{$endTag}">
      <xsl:call-template name="attribs">
        <xsl:with-param name="attrlist"
select="substring-after(normalize-space($tag),' ')"/>
      </xsl:call-template>
      <xsl:call-template name="parse">
        <xsl:with-param name="str" select="$value"/>
      </xsl:call-template>
    </xsl:element>
  </xsl:template>

  <xsl:template name="attribs">
    <xsl:param name="attrlist" select="''"/>
    <xsl:variable name="name"
select="normalize-space(substring-before($attrlist,'='))"/>
    <xsl:if test="$name">
      <xsl:variable name="value">
        <xsl:choose>
          <xsl:when test="substring-before($attrlist,'=&quot;')">
            <xsl:value-of
select="substring-before(substring-after($attrlist,'=&quot;'),'&quot;')"/>
          </xsl:when>
          <xsl:when test="substring-before($attrlist,'= &quot;')">
            <xsl:value-of
select="substring-before(substring-after($attrlist,'= &quot;'),'&quot;')"/>
          </xsl:when>
          <xsl:when test="substring-before($attrlist,&quot;=&apos;&quot;)">
            <xsl:value-of
select="substring-before(substring-after($attrlist,&quot;=&apos;&quot;),&quo
t;&apos;&quot;)"/>
          </xsl:when>
          <xsl:when test="substring-before($attrlist,&quot;= &apos;&quot;)">
            <xsl:value-of
select="substring-before(substring-after($attrlist,&quot;
=&apos;&quot;),&quot;&apos;&quot;)"/>
          </xsl:when>
        </xsl:choose>
      </xsl:variable>
      <xsl:attribute name="{$name}">
        <xsl:value-of select="$value"/>
      </xsl:attribute>
    </xsl:if>
    <xsl:choose>
      <xsl:when test="contains($attrlist,' ')">
        <xsl:call-template name="attribs">
          <xsl:with-param name="attrlist" select="substring-after($attrlist,
' ')"/>
        </xsl:call-template>
      </xsl:when>
    </xsl:choose>
  </xsl:template>

(...)

Hope this helps you

Regards,
Américo Albuquerque



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.