[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Selecting and printing certain nodes


Subject: Re: [xsl] Selecting and printing certain nodes
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 19 Feb 2004 23:34:12 GMT

         <xsl:with-param name="do-sect" select="$foreachNode/*" />

You threw away all the text at that pont, as * selects element nodes
(only) If you want all child nodes use /node() not /* at the end.

It still seems highly likely that a much more simple apply-templates
based solution is possibe rather than an explicitly recursive template.


side issue, usual complaint about misuse of word tag

  I need to output all the text inside the tags

It seems every one misuses tag like this but I'm not sure why. tag has a
very specific meaning, and tags are opened with < (what used to be
called STAGO: start tag open character) and closed with > (what used to
be called STAGC) the stuff inside a tag consists of the element name,
some attribute markup and some ignorable white space. You want the text
that is explictly _not_ inside the tags. (I know this seems pedantry,
but it really does make it harder to understand the problem when people
say exactly the oposite of what they mean) 

  I need to output all the text inside the tags (expect for the
  "variable" and "replace" tags.

Why can't you just use the identity template, as Wendell suggested,
together with a couple of templates for the variable and replace
_elements_.?

"cdata" is also a slightly confusing name for the param as CDATA also
has a technical meaning but (in XML but not SGML) CDATA declared text
can only appear in attribute values, not in element content.



David

I'm not sure I fully understood your requirement but this copies your
foreach stuff 4 times, replacing <var/> with a dev 1... each time.


var1.xml
<doc>
<item>dev1</item>
<item>dev2</item>
<item>dev3</item>
<item>dev4</item>
</doc>


var2.xml
<foreach param="devices">
<tr><td><b>BOLDFACE</b> Some <var/> Text</td><td>Here</td></tr>
<tr><td> Test11</td><td>Test</td></tr>
</foreach>


var3.xsl
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="*">
<xsl:param name="var"/>
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates>
  <xsl:with-param name="var" select="$var"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>

<xsl:template match="foreach">
<xsl:param name="var"/>
<xsl:variable name="here" select="."/>
<xsl:for-each select="document('var1.xml')/doc/item">
<div>
<xsl:apply-templates select="$here/node()">
  <xsl:with-param name="var" select="."/>
</xsl:apply-templates>
</div>
</xsl:for-each>
</xsl:template>

<xsl:template match="var">
<xsl:param name="var"/>
<span><xsl:value-of select="$var"/></span>
</xsl:template>
</xsl:stylesheet>



$ saxon var2.xml var3.xsl
<?xml version="1.0" encoding="utf-8"?><div>
<tr><td><b>BOLDFACE</b> Some <span>dev1</span>
Text</td><td>Here</td></tr>
<tr><td> Test11</td><td>Test</td></tr>
</div><div>
<tr><td><b>BOLDFACE</b> Some <span>dev2</span>
Text</td><td>Here</td></tr>
<tr><td> Test11</td><td>Test</td></tr>
</div><div>
<tr><td><b>BOLDFACE</b> Some <span>dev3</span>
Text</td><td>Here</td></tr>
<tr><td> Test11</td><td>Test</td></tr>
</div><div>
<tr><td><b>BOLDFACE</b> Some <span>dev4</span>
Text</td><td>Here</td></tr>
<tr><td> Test11</td><td>Test</td></tr>
</div>



-- 
http://www.dcarlisle.demon.co.uk/matthew

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



Current Thread
Keywords
xml