xsl-list
[Top] [All Lists]

RE: mixed content nodes question

2005-01-07 12:10:31

Hi Jeb,

From: Jeb Boniakowski [mailto:jeb(_at_)protosw(_dot_)com]

<...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




--~------------------------------------------------------------------
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>
--~--