[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Insert character for missing nodes

Subject: Insert character for missing nodes
From: "Jesse Gillies" <jessegillies@xxxxxxxxx>
Date: Thu, 30 Oct 2008 10:21:25 -0400
 Insert character for missing nodes
Hello,

I am converting XML files to pipe-delimited text files using xsltproc
and xslt version 1. The problem I'm having is that in my XML file,
every possible child node is not present under every parent node.
Here's an example:

<business>
  <name>Hot Dog Stand</name>
  <address>123 Main St</address>
  <url>http://www.hotdogstand.com</url>
</business>
<business>
  <name>Joe's Pizza</name>
  <address>213 Pine St</address>
</business>

Because Joe's Pizza is missing the url node, I don't get a pipe, which
throws off my columns. Is there a way to test for all possible nodes,
and where any are missing, to insert a character?

Here's what I've got so far in my xsl file (I'm excluding the reviews
node because I'm creating separate flat files for the data in that
node):

<xsl:template match="business">
  <xsl:for-each select="*[not(self::reviews)]">
   <xsl:value-of select="."/>
   <xsl:if test="position() != last()">
    <xsl:value-of select="'|'"/>
   </xsl:if>
   </xsl:for-each>
  <xsl:text>&#10;</xsl:text>
</xsl:template>

Thanks,
Jesse

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.