Subject: RE: [xsl] mixed content nodes question From: "Mark Lundquist" <ml@xxxxxxxxxxxxxx> Date: Fri, 7 Jan 2005 11:10:31 -0800 |
Hi Jeb, > From: Jeb Boniakowski [mailto:jeb@xxxxxxxxxxx] > > <...snip...> > I'd imagine I'd have some part of my xsl sheet include a long 'when' > block and switch on the lookup attribute's values so i'd have: > <xsl:when test="3">Foo</xsl:when> > <xsl:when test="4">Bar</xsl:when> > > But I can't figure out how to do the actual transforming of only those > <dictionary> tags in place, leaving the rest of the file unchanged. > I've tried apply-templates in the a template matching "/", then having > a template matching "*" do a test to see if the current node is > <dictionary>, if so, transform and write out, otherwise, write out as > it is, but I can't get it to work right. > > If it's vastly easier to process if instead of having: > <dictionary lookup="3"/> -> Foo > I have: > <dictionary>3</dictionary> -> Foo > > I might be able to make that change to the xml format, but I'm still > confused about how to deal with mixed nodes. I feel like people must > do this all the time, if they have bits of HTML embedded in larger XML > trees they must have markup tags like <b>, <a> that make the nodes > mixed content Indeed... all the time. First of all, you need a template like this: <xsl:template match="node() | @*"> <xsl:copy> <xsl:apply-templates select="node() | @*" /> </xsl:copy> </xsl:template> Later, read http://www.dpawson.co.uk/xsl/sect2/defaultrule.html to learn what you are fixing with the above template :-). I put that template in its own stylesheet and then do something like <xsl:import href="xlst/common/identity.xslt" /> from all my other stylesheets that need this. But for now, you can just write the template inline. Then, add a template like this: <xsl:template match="dictionary"> <xsl:if test="@lookup = '3'">Foo</xsl:if> <xsl:if test="@lookup = '4'">Bar</xsl:if> <xsl:/template> The above template uses the "@" shorthand notation for the attribute:: axis, which you can read up on later. HTH, Mark
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] mixed content nodes quest, Jim Neff | Thread | Re: [xsl] mixed content nodes quest, António Mota |
RE: Re: [xsl] Group various element, cknell | Date | Re: [xsl] mixed content nodes quest, António Mota |
Month |