October 23rd, 2002, 11:54 PM
-
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?
October 24th, 2002, 12:27 AM
-
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
October 24th, 2002, 12:31 AM
-
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!