Re: [xsl] Conditional extraction of data

Subject: Re: [xsl] Conditional extraction of data
From: Bryan Rasmussen <bry@xxxxxxxxxx>
Date: Mon, 8 Nov 2004 14:59:18 +0100
-- 
Bryan Rasmussen

I believe this should solve your problem, if I've understood it.

<xsl:template match="tag1 | tag3 | tag4">
<xsl:copy><xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="tag2">
<i><xsl:apply-templates/></i>
</xsl:template>

always assuming that you have not defined a template for text()
and assuming that you don't have any requirements for doing stuff that can't be
done, like copying cdata as is.
also assuming that there is not requirement to keep whitespace as is in the
original content. 




Quoting "Bradley, Peter" <PBradley@xxxxxxxxxx>:

> It pays to be honest, so I'll be up-front about this.  The question arises
> from an assignment on a course I'm doing.
> 
> However, I don't want to cheat, so I'll try to form the question in the most
> general way that I can:
> 
> The purpose of the exercise is to convert some xml to html.  I have a
> repeating element under the root - let's call it anElement.  Initially, the
> requirement was to output all its contents, unchanged.  So I could do this:
> 
> <xsl:for-each select="anElement">
> 	<xsl:value-of select="." />
> </xsl:for-each>
> 
> The anElement element has mixed content and would be described in a DTD as
> follows:
> 
> <!ELEMENT anElement (#PCDATA | tag1 | tag2 | tag3 | tag4)* >
> 
> All the child tags contain #PCDATA only.
> 
> The new requirement is to print all the content as before, but to print the
> contents of tag2 (say) in italics - i.e. surround its contents with <i></i>
> html tags.
> 
> I've sweated over this all weekend and can't work out how to solve it.  If I
> treat each tag individually in a for-each or an apply-templates/template
> combination (if that makes sense), I can't see how to output the #PCDATA in
> anElement.
> 
> Any help would be appreciated - especially a pointer to a resource that will
> let me work it out for myself.  I've tried the obvious places like w3c
> schools.
> 
> Thank for your attention
> 
> 
> Peter

Current Thread