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"?>
  <txt>lorem ipsum <entity>alpha</entity> dolorem est</txt>
<!-- entity.xsl -->
<xsl:stylesheet version="1.0" xmlns:xsl="">
<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 match="txt">
  <xsl:message terminate="no">-- txt template --</xsl:message>
  <xsl:for-each select="*">
      <xsl:when test="text()">
      <xsl:when test="entity">
        <xsl:apply-templates select="entity"/>
  <xsl:apply-templates select="entity"/>
<xsl:template match="entity">
  <xsl:message terminate="no">-- entity template --</xsl:message>
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