xsl-list
[Top] [All Lists]

RE: copy-of problem...

2003-07-15 07:17:55
Hi

-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of 
David(_dot_)Pawson(_at_)rnib(_dot_)org(_dot_)uk
Sent: Monday, July 14, 2003 12:01 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] 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



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