#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14

    Applying template to marked up PCDATA


    Say I have element definitions like so:
    Code:
    <!ELEMENT root (#PCDATA|markup1|markup2)*>
    <!ELEMENT markup1 (#PCDATA)>
    <!ELEMENT markup2 (#PCDATA)>
    An example would be,
    Code:
    <root>
        This is some<markup1>text</markup1>.
        Some of the words are <markup2>important</markup2>.
    </root>
    And the xsl templates may be something like:
    Code:
    <xsl:template match="/">
        <html>
            <body>
                <!-- Parsed content should go here. -->
            </body>
        </html>
    </xsl:template>
    <xsl:template match="markup1">
        <span color="green"><xsl:value-of select="." /></span>
    </xsl:template>
    <xsl:template match="markup2">
        <span color="blue"><xsl:value-of select="." /></span>
    </xsl:template>
    I can't figure out how to apply the templates in their node's position relative to the parsed character data. Using an apply-templates directive only returns applied child nodes, and a value-of directive on the root element doesn't apply the child node templates. How do you do it?
  2. #2
  3. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    You need a template rule to match text nodes. Then you can use apply-templates.

    <xsl:template match="text()">
    <xsl:value-of select="." />
    </xsl:template>
    -james
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    Well, yeah, that's what I thought.

    It's working now. I still have no clue why it wasn't earlier. I swear I did that, I even said that it didn't work because I tried it. I must have had a typo, weird though that it still validated...

    Anyways, thanks!

IMN logo majestic logo threadwatch logo seochat tools logo