xsl-list
[Top] [All Lists]

Re: [xsl] Insert character for missing nodes

2008-10-30 11:52:59
Jesse Gillies schrieb:

<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?

Very often in XSLT, your process is mainly data-driven. The program
reacts to input.

In your example, however, you want to guarantee a certain structure that
may be missing in your input. A simple way to guarantee this structure
is to code it in your program:

  <xsl:template match="business">
    <xsl:copy>
      <name><xsl:value-of select="name"/></name>
      <address><xsl:value-of select="address"/></address>
      <url><xsl:value-of select="url"/></url>
    </xsl:copy>
  </xsl:template>

This would be step 1 in what Martin already suggested for 1.0.

You may also simply leave out the element constructors (like
<name>...</name>) and separate your <xsl:value> elements by
<xsl:text>|</xsl:text> to guarantee the pipe-structure. This
works for 1.0, too.

Michael Ludwig

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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