<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="UTF-8" />
<xsl:strip-space elements="*" />
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="root">
<root>
<xsl:apply-templates />
</root>
</xsl:template>
<xsl:template match="child">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="leaf">
<xsl:variable name="digit">
<xsl:if test="./dictionary"><xsl:value-of select="./dictionary"
/></xsl:if>
</xsl:variable>
<xsl:variable name="frag">
<xsl:choose>
<xsl:when test="./dictionary/@lookup='3'">Foo</xsl:when>
<xsl:when test="./dictionary/@lookup='4'">Bar</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<leaf><xsl:value-of select="substring(.,1,string-length(.)-2)" /> <xsl:value-of select="$frag"
/> <xsl:value-of select="substring(.,string-length(.)-1,string-length(.))" /></leaf>
</xsl:template>
</xsl:stylesheet>
--
Charles Knell
cknell(_at_)onebox(_dot_)com - email
-----Original Message-----
From: Jeb Boniakowski <jeb(_at_)protosw(_dot_)com>
Sent: Fri, 7 Jan 2005 13:35:38 -0500
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] mixed content nodes question
Hi--
I'm really new to XSL and I'm having trouble figuring out how to do
what seem to be fairly basic things. For example, say I have the
following file:
<root>
<child>
<leaf>Leaf Value1</leaf>
<leaf>Leaf Value2</leaf>
</child>
<child>
<leaf>Leaf Value <dictionary lookup="3"/> 3</leaf>
</child>
</root>
and I wanted to transform it very simply to:
<root>
<child>
<leaf>Leaf Value1</leaf>
<leaf>Leaf Value2</leaf>
</child>
<child>
<leaf>Leaf Value Foo 3</leaf>
</child>
</root>
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, but I can't find a good example of it.
Also, I keep coming across vague references to the fact that MSXSL.exe
v3 is perhaps not the ideal way of transforming my xml docs. Given
that I'm on windows, is there a better tool to use?
Any help or pointers to help would be greatly appreciated,
jeb.
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--