troubleshooting Question

XSLT processing text and element nodes

Avatar of tjgquicken
tjgquicken asked on
Web Languages and Standards
3 Comments1 Solution499 ViewsLast Modified:
I'm having trouble figuring out how to write a template that can take as input a result tree that contains element nodes intermingled with text nodes and output the nodes in order, applying a template to each of the element nodes. I hope the code snippet I attached will make that clearer: I want it to print out:

lorem ipsum [lowercase alpha symbol] dolorem est
<!-- entity.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <txt>lorem ipsum <entity>alpha</entity> dolorem est</txt>
</root>
 
<!-- entity.xsl -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
 
<xsl:template match="root">
  <xsl:message terminate="no">-- root template --</xsl:message>
  <xsl:apply-templates select="txt"/>
</xsl:template>
 
<xsl:template match="txt">
  <xsl:message terminate="no">-- txt template --</xsl:message>
  <xsl:for-each select="*">
    <xsl:choose>
      <xsl:when test="text()">
        <xsl:copy/>
      </xsl:when>
      <xsl:when test="entity">
        <xsl:apply-templates select="entity"/>
      </xsl:when>
    </xsl:choose>
  </xsl:for-each>
  <xsl:apply-templates select="entity"/>
</xsl:template>
 
<xsl:template match="entity">
  <xsl:message terminate="no">-- entity template --</xsl:message>
  <xsl:text>&#945;</xsl:text>
</xsl:template>
 
</xsl:stylesheet>
ASKER CERTIFIED SOLUTION
Gertone (Geert Bormans)
Information Architect
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros