[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Conditional extraction of data

Subject: Re: Conditional extraction of data
From: Bryan Rasmussen <bry@xxxxxxxxxx>
Date: Mon, 8 Nov 2004 14:59:18 +0100
bryan rasmussen
-- 
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.