Re: [xsl] Process some elements, but not others... SOLVED!

Subject: Re: [xsl] Process some elements, but not others... SOLVED!
From: Ted Stresen-Reuter <tedmasterweb@xxxxxxx>
Date: Fri, 14 Feb 2003 14:19:25 -0600
Thank you! That minor clarification was what I needed to get it.

The only change I made to your suggestion was to add <xsl:copy> to it as Mike Brown suggested in an earlier message. So here is how the XSL ended up looking...

<xsl:template match="attribute">
<!-- we do a bunch of fun transofrmations here -->
<xsl:value-of select="@name" />
<xsl:value-of select="@type" />
<!-- would like to have the value of the description node here, but
with all HTML elements left in tact and all "ref" elements transformed -->
<xsl:apply-templates select="description"/>
</xsl:template>


<xsl:template match="description">
     <xsl:apply-templates/>
</xsl:template>

<xsl:template match="@*|node()">
     <xsl:copy>
          <xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
     </xsl:copy>
</xsl:template>

<xsl:template match="ref">
<xsl:choose>
<xsl:when test="@type = 'attr'">
<a href="{text()}.html" class="ref"><xsl:value-of select="text()" /></a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="text()" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>


On Friday, February 14, 2003, at 01:46 PM, Roger Glover wrote:

Ted Stresen-Reuter wrote:

I've tried a variety of variations on the procedure you suggest, but it
just doesn't seem to work, so, I'm reposting the question with a little
better example...


Sample XML
<HtdigAttributes>
     <attribute name="accents_db" type="string_list" programs="htdig">
	<example>search_algorithm, search_results_header</example>
          <description>
              <p>bla bla bla bla bla bla <strong>bla bla</strong> bla
bla bla <em>bla</em></p>
              <p>bla bla <ref>bla</ref> bla, bla!</p>
          </description>
     </attribute>
</HtdigAttributes>

Sample XSL
<xsl:output method="xml"

doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"
doctype-public="-//W3C/DTD XHTML 1.0 Transitional//EN" indent="yes"
encoding="ISO-8859-1" />


<xsl:template match="/">
     <xsl:apply-templates />
</xsl:template>

<xsl:template match="HtdigAttributes">
     <xsl:apply-templates select="attribute" />
</xsl:template>

<xsl:template match="attribute">
<!-- we do a bunch of fun transofrmations here -->
<xsl:value-of select="@name" />
<xsl:value-of select="@type" />
<!-- would like to have the value of the description node here, but
with all HTML elements left in tact and all "ref" elements transformed
-->
</xsl:template>


Any suggestions on changes that would make your suggestion work in this
context?

There have been at least a couple of examples posted that, were you to add
them at the point of your last comment, would be a starting point to a
solution. The thing that is missing here (and has been missing from the
beginning, at least for me) is the desired output. Specifically, into
**what form** do you to wish to transform the <ref> elements?


Without that info I could not do much more than what others have already
posted. But that's never stopped me before!! Here is an attempt on my
part, starting with the last template you wrote and moving forward.


=================================
<xsl:template match="attribute">
<!-- we do a bunch of fun transofrmations here -->
<xsl:value-of select="@name" />
<xsl:value-of select="@type" />
<!-- would like to have the value of the description node here, but
with all HTML elements left in tact and all "ref" elements transformed -->
<xsl:apply-templates select="description"/>
</xsl:template>


<xsl:template match="description">
     <xsl:apply-templates/>
</xsl:template>

<xsl:template match="@*|node()">
     <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
     </xsl:copy>
</xsl:template>

<xsl:template match="ref">
     <!-- (: Oh won't you do, that voodoo, that you do, so well! :) -->
</xsl:template>
=================================

This is all untested code, "off the top of my head". As such it may contain
syntax errors. But you should be able to get the general idea of what to do
from this.


I hope this is helpful!


-- Roger Glover glover_roger@xxxxxxxxx



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



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


Current Thread