[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: presenting xml elements as they appear in the sour
Subject: Re: presenting xml elements as they appear in the source file
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 27 Apr 2010 14:21:52 -0400
|
Rod,
If all you need to do is output an element's name in "tags", that's as easy as:
<xsl:template match="*">
<span class="tag">
<xsl:text><</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>></xsl:text>
</span>
<xsl:apply-templates/>
<span class="tag">
<xsl:text></</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text>></xsl:text>
</span>
</xsl:template>
On the other hand, your requirements are probably more complex. Maybe
you want line feeds and indenting, maybe you need to show attributes
or other node types, etc. etc.
Eventually you may want an entire XML serializer implemented in XSLT.
This has been done too, but some problems on the edge such as
escaping < and & characters, or serializing namespace desclarations,
can make it fairly tricky. At that point you may want to check out
someone else's library, like Evan Lenz's at
http://lenzconsulting.com/xml-to-string/.
Cheers,
Wendell
At 01:54 PM 4/27/2010, you wrote:
Hello,
In general can anyone suggest how to display xml nodes as they
appear in the source file?
If there is an easy way of doing this it will assist with this problem:
I'd like to use xsl to prepare an html document but at certain
points the xml becomes an arbitrary mix of nodes, think of a number
of a number of legal/valid elements that can be arranged in
arbitrary ways, such as a nested query.
Since the composition of the query is unpredictable it is necessary
to just present the nodes as they are in the source xml, complete
with the < > brackets, to make things easy.
I see that there are examples of presenting xml in trees and that
may be a bit time consuming for a beginner to implement so simply
listing the elements verbatim is fine for now.
Thank you
Rod
======================================================================
Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc. http://www.mulberrytech.com
17 West Jefferson Street Direct Phone: 301/315-9635
Suite 207 Phone: 301/315-9631
Rockville, MD 20850 Fax: 301/315-8285
----------------------------------------------------------------------
Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|