We help IT Professionals succeed at work.

xslt value-of select stops at first value

tnapolitano
tnapolitano asked
on
Medium Priority
378 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.
Comment
Watch Question

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  

Author

Commented:

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

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

Author

Commented:
Thanks for getting back to me on this.

Any sources you can point me to on scripting the modification/reformat of a xml document?
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanks. The more I thought about it, the better I decided modifying the structure and creating a new XML doc will work.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.