Subject: Re: [xsl] super basic xsl question From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Thu, 13 Jan 2005 13:45:54 -0500 |
In this particular case, though, I want the template that matches the value of <child> to be agnostic to the markup that is in there, with no more template processing, I just want whatever was already done (by this point, that chunk of xml has been processed by other sheets, and will be processed by later sheets) so I didn't want to do an explicit match for the link tag.
In general though, on the topic of apply-templates, there is a larger issue that trips me up. Oftentimes, it seems that I mess up my set of templates in such a way that things get matched and copied to the output tree automatically, even though they are matched. To deal with this, I've been sticking a template at the top of my sheets that is:
<xsl:template match="text()"/>
Is this bad style?
Is it a crappy hack to deal with messed up templates?
Or is it the correct way to suppress default rules?
I have situations where I have things along the lines of:
<node> <description>Foo</description> <datum>1</datum> <datum>2</datum> </node>
When I do something like:
<xsl:template match="node"> <h1><xsl:value-of select="description"/></h1> <ul><xsl:apply-templates/><ul> </xsl:template>
<xsl:template match="node/datum"> <li><xsl:value-of select="."/></li> </xsl:template>
I end up with:
<h1>Foo</h1> Foo <!-- Extraneous foo that I don't want --> <ul> <li>1</> <li>2</2> </ul>
Tacking a <xsl:template match="text()"/> seems to catch the 'Foo' and kill it, but why do I have to do this?
<xsl:template match="node"> <xsl:apply-templates select="description"/> <ul> <xsl:apply-templates select="datum"/> <ul> </xsl:template>
<xsl:template match="node/description"> <xsl:apply-templates/> </xsl:template>
<xsl:template match="node/datum"> <li><xsl:apply-templates/></li> </xsl:template>
<xsl:template match="node"> <xsl:apply-templates/> </xsl:template>
Does the <apply-templates/> in node automatically copy the text values of any child nodes that are not explicitly matched?
<xsl:template match="*"> <xsl:apply-templates/> </xsl:template>
Is it better to have an additional template that specifically matches 'description' and does nothing?
Or to take the <h1><xsl:value-of select="description"/></h1> out and move it into this explicit template? Or should I be doing something more like <xsl:apply-templates select="datum"/>?
<html> <head> <title><xsl:value-of select="/path/to/title"/></head> </head> ... </html>
Enjoy! Wendell
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] super basic xsl question, Michael Kay | Thread | RE: [xsl] super basic xsl question, Mark Lundquist |
RE: [xsl] binary XML, Michael Kay | Date | [xsl] Transform 2 xml streams to 1 , Bhaskar, Rajan |
Month |