tags:

views:

78

answers:

2

I have some very basic XML:

<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
<string>One</string>
<string>Two</string>
</ArrayOfString>

How can I translate this into:

<ul>
 <li>One</li>
 <li>Two</li>
</ul>

Using XLST?

Previously I've worked with a:vlaue but these are just strings?

+1  A: 

Is something like this what you want?

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
<xsl:template match="/">
    <ul>
    <xsl:apply-templates />
    </ul>
</xsl:template>
<xsl:template match="string">
    <li><xsl:value-of select="text()"></xsl:value-of></li>
</xsl:template>
</xsl:stylesheet>

It produces the following output for me:

<?xml version='1.0' ?>
<ul>
<li>One</li>
<li>Two</li>
</ul>
robertc
Your template for "/" works "by accident" only. You should make templates explicit instead of trusting implicit default rules to do the right thing. As soon as an actual template for `ArrayOfString` was defined elsewhere in the stylesheet, this solution would break.
Tomalak
Fair enough. I just started with the base XSL template my editor provided and added stuff until it worked :)
robertc
Which editor do you use?
danit
I have Stylus Studio 2007 - don't do much with XML these days so it's not been upgraded: http://www.stylusstudio.com/xml_product_index.html
robertc
+2  A: 

I'd do:

<xsl:stylesheet 
  version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  
>
  <xsl:template match="ArrayOfString">
    <ul>
      <xsl:apply-templates select="string" />
    </ul>
  </xsl:template>

  <xsl:template match="string">
    <li>
      <xsl:value-of select="." />
    </li>
  </xsl:template>
</xsl:stylesheet>
Tomalak