Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

xslt value-of select stops at first value

Posted on 2006-03-29
6
Medium Priority
?
339 Views
Last Modified: 2010-04-17
XSLT noob here, and I would appreciate any help, hints or suggestions.

I have a XML structured like this (this is an application-generated xml that I cannot modify):

<doc>

<host>hostname1</host>
<ip>192.168.1.100</ip>
<os>windows xp</os>
<host>hostname2</host>
<ip>192.168.1.101</ip>
<os>mac os x</os>

</doc>


I have a XSL structured like this:


<xsl:template match="/" >

<html>

<body>

<h2>System Summary</h2>
<table border="1">

<tr>

<th align="left">Host</th>
<th align="left">IP Address</th>
<th align="left">Operating System</th>


</tr>

<xsl:for-each select="/Doc" >
<tr>

<td><xsl:value-of select="hostname" /></td>

<td><xsl:value-of select="ip" /></td>

<td><xsl:value-of select="os" /></td>


</tr>
</xsl:for-each>
</table>
</body>
</html>

</xsl:template>


My output stops at the first value per element (i.e., "hostname1, 192.168.1.100, Windows XP").

What do I do to make the XSLT continue through all elements of the XML? Thanks in advance.
0
Comment
Question by:tnapolitano
  • 3
  • 3
6 Comments
 
LVL 14

Expert Comment

by:nayernaguib
ID: 16328201
Change the XML document to look like this:

_______________________________________

<doc>
      <host>
            <hostname>hostname1</hostname>
            <ip>192.168.1.100</ip>
            <os>windows xp</os>
      </host>
      <host>
            <hostname>hostname2</hostname>
            <ip>192.168.1.101</ip>
            <os>mac os x</os>
      </host>
</doc>

_______________________________________

Next, replace the statement

  <xsl:for-each select="/Doc" >
 
with the statement

  <xsl:for-each select="/Doc/host" >

_______________

  Nayer Naguib  
0
 
LVL 3

Author Comment

by:tnapolitano
ID: 16328918

Thanks for getting back to me. But this is an XML generated by an application and modification is not an option.

0
 
LVL 14

Expert Comment

by:nayernaguib
ID: 16329379
Modifying the XML document manually or using a small program to automate the task is not the problem. You will not get the required output (using XSLT) unless you modify the XML file structure.

_______________

  Nayer Naguib
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:tnapolitano
ID: 16335801
Thanks for getting back to me on this.

Any sources you can point me to on scripting the modification/reformat of a xml document?
0
 
LVL 14

Accepted Solution

by:
nayernaguib earned 1000 total points
ID: 16342483
Take a look at these pages on how to programmatically read/write XML files. It should take a few lines to read the file and store it in memory, and a few other lines to write the file with the new structure.

  http://samples.gotdotnet.com/quickstart/howto/doc/Xml/ReadXMLFile.aspx
  http://samples.gotdotnet.com/quickstart/howto/doc/Xml/WriteXMLFile.aspx

You can find a lot of online resources on how to do that using other programming/scripting languages.

_______________

  Nayer Naguib
0
 
LVL 3

Author Comment

by:tnapolitano
ID: 16344342
Thanks. The more I thought about it, the better I decided modifying the structure and creating a new XML doc will work.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
Simple Linear Regression
Starting up a Project

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question