• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XSL/XML document structure question

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know if there is a way to make XSL read in a node list and
then sequentially go through it(outputting certain things for different
nodes in the order they appear in the xml doc), instead of outputting each
node that is the same together?
Like if you had the following xml:
<textfield>
<textname>firstName</textname>
</textfield>
<combo>
<cmboname>cmboNat</cmboname>
</combo>
<textfield>
<textname>firstName</textname>
</textfield>
the xsl would output a textfield then a combo and then a textfield instead
of two textfields and a combo or vice versa.
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Brendan
You should change your xml file to
<control controlType="Text">
<textname>firstName</textname>
</control>
<control controlType="combo">
<cmboname>cmboNat</cmboname>
</control>
<control controlType="Text">
<textname>firstName</textname>
</control>
Your xsl file should then include
<xsl:for-each select="control">
<xsl:choose>
<xsl:when test="@controlType='Text'">
...code to display text box..
</xsl:when>
<xsl therwise>
...code to display combo box...
</xsl therwise>
</xsl:choose>
</xsl:for-eahc>

frank
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In XSLT there are two approaches to get data from XML document: �pull� and �push�. You pull data when you are using such elements as <xsl:for-each>, <xsl:value-of select>... If, instead, you want to get your data �how they are�, you can write a template for each element you want to see in the output and apply all this templates with <xsl:apply-templates/> element. XSLT processor walks through input tree and for each element applies matching template. Here is your XML document (I added root element and changed content of the last textname to �secondName� with illustrative purpose)
<?xml version="1.0"?>
<root>
<textfield>
<textname>firstName</textname>
</textfield>
<combo>
<cmboname>cmboNat</cmboname>
</combo>
<textfield>
<textname>secondName</textname>
</textfield>
</root>
XSL:
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="textname">
<!-- ... some processing here, like -->
<b><xsl:value-of select="."/></b>
</xsl:template>
<xsl:template match="cmboname">
<!-- ... some other processing here, like -->
<i><xsl:value-of select="."/></i>
</xsl:template>
</xsl:stylesheet>
the output is:
firstName cmboNat secondName

[This message has been edited by Mapraputa Is (edited June 21, 2001).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic