xsl-list
[Top] [All Lists]

Re: Traverse XML Source Part 2

2004-08-19 09:07:51
Hi Karl,
Please try this XSL -

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">

<xsl:output method="html" />

<xsl:template match="node()">
  <xsl:if test="count(child::*) &gt; 0">
     <ul>
       <xsl:value-of select="name()"/>
       <xsl:apply-templates />
     </ul>
  </xsl:if>
  <xsl:if test="count(child::*) = 0">
    <li>
      <xsl:value-of select="concat(name(),' = ',.)"/>
    </li>
  </xsl:if>
</xsl:template>

<xsl:template match="processing-instruction()" />

</xsl:stylesheet>

The XML part -

<REST_OF_SONG>
  They all ran after the farmer's wife,<BR/>Who cut
off their tails with a carving knife,<BR/>Did you ever
see such a thing in your life,<BR/>As three blind
mice?
</REST_OF_SONG>

would still cause some problems.. Can you please
explain the pattern of this tag?

Regards,
Mukul

--- karl(_at_)meetscoresonline(_dot_)com wrote:

Mukul: (please, this thread is open to all for
comment/suggestion)
It seems I am doing something a bit wrong... but the
match on node() seems
to occur 2 times.  I have included the output, as
well the source.  Also,
how do we avoid the:
<?xml-stylesheet type="text/xsl"
href="xsl_docs/important_stuff.xsl"?>
From the node match?

XML SOURCE
======================
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl"
href="xsl_docs/important_stuff.xsl"?>
<A_RHYME>
      <THREE_BLIND_MICE>
              <VERSE_1>
                      <word>Three</word>
                      <word>blind</word>
                      <word>mice</word>
              </VERSE_1>
              <VERSE_2>
                      <word>Three</word>
                      <word>blind</word>
                      <word>mice</word>
              </VERSE_2>
              <VERSE_3>
                      <word>See</word>
                      <word>how</word>
                      <word>they</word>
                      <word>run</word>
              </VERSE_3>
              <VERSE_4>
                      <word>See</word>
                      <word>how</word>
                      <word>they</word>
                      <word>run</word>
              </VERSE_4>
      </THREE_BLIND_MICE>
      <MORE>
              There is more to the poem
      </MORE>
      <REST_OF_SONG>
              They all ran after the farmer's wife,<BR/>Who cut
off their tails with a
carving
              knife,<BR/>Did you ever see such a thing in your
life,<BR/>As three
blind mice?
      </REST_OF_SONG>
</A_RHYME>
======================
END XML SOURCE

XSL SOURCE
======================
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">

<xsl:template match="node()">
              <xsl:if test="count(child::*)&gt;0">
                      <ul>
                              <xsl:value-of select="name()"/>
                              <xsl:apply-templates />
                      </ul>
              </xsl:if>
              <xsl:if test="count(child::*)=0">
                      <li>
                              <xsl:value-of select="concat(name(),' = ',.)"/>
                              <xsl:apply-templates />
                      </li>
              </xsl:if>
</xsl:template>

</xsl:stylesheet>
======================
END XSL SOURCE

HTML OUTPUT
======================
<LI>xml-stylesheet = type="text/xsl"
href="xsl_docs/important_stuff.xsl"
<UL>A_RHYME
<UL>THREE_BLIND_MICE
<UL>VERSE_1
<LI>word = Three
<LI>= Three
<LI>word = blind
<LI>= blind
<LI>word = mice
<LI>= mice</LI></UL>
<UL>VERSE_2
<LI>word = Three
<LI>= Three
<LI>word = blind
<LI>= blind
<LI>word = mice
<LI>= mice</LI></UL>
<UL>VERSE_3
<LI>word = See
<LI>= See
<LI>word = how
<LI>= how
<LI>word = they
<LI>= they
<LI>word = run
<LI>= run</LI></UL>
<UL>VERSE_4
<LI>word = See
<LI>= See
<LI>word = how
<LI>= how
<LI>word = they
<LI>= they
<LI>word = run
<LI>= run</LI></UL></UL>
<LI>MORE = There is more to the poem
<LI>= There is more to the poem
<UL>REST_OF_SONG
<LI>= They all ran after the farmer's wife,
<LI>BR =
<LI>= Who cut off their tails with a carving knife,
<LI>BR =
<LI>= Did you ever see such a thing in your life,
<LI>BR =
<LI>= As three blind mice? </LI></UL></LI></UL></LI>
======================
END HTML OUTPUT




                
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 


<Prev in Thread] Current Thread [Next in Thread>