nested xml nodes to xsl

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
All: I am just starting on XML-XSL coding. Please no VB or LINQ references and thanks.
I have XML generated by XMLWriter that has multiple nested sets of nodes:
<pre class="prettyprint <?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="loco-config.xsl" type="text/xsl"?>

<ConfigurationVersionList type="ConfigurationVersionList
<ConfigValidity type="ConfigurationValidity" Numeric="1 ConfigValidPreferred</ConfigValidity>
<ConfigValidityDT type="DateTime 2012-02-10T20:47:41Z</ConfigValidityDT>
<Scac type="String ABCDE</Scac>
<ConfigurationVersionCRC type="UInt32 404739939</ConfigurationVersionCRC>
<RepositoryList type="Dictionary`2" genericParam0="String" genericParam1="Repository
<Entry>
<String type="String" dict="key software</String>
<Repository type="Repository" dict="value
<FilesetList type="List`1" genericParam0="FileSet
<FileSet type="FileSet
<Version type="String 1.0</Version>
<Hash type="UInt32 123456789</Hash>
<FilesetStatus type="FileSetStatus" Numeric="1 Preferred</FilesetStatus>
<FilesetID type="Int32 16</FilesetID>
<RepositoryName type="String software1</RepositoryName>
</FileSet>

<FileSet type="FileSet
<Version type="String 1.1</Version>
<Hash type="UInt32 987654321</Hash>
<FilesetStatus type="FileSetStatus" Numeric="2 Preferred</FilesetStatus>
<FilesetID type="Int32 13</FilesetID>
<RepositoryName type="String software2</RepositoryName>
</FileSet>
</FilesetList>
<ReposStatus type="Int32 42</ReposStatus>
<ReposId type="Int32 1</ReposId>
<RepositoryName type="String software3</RepositoryName>
</Repository>
</Entry>
<Entry>
<String type="String" dict="key common</String>
<Repository type="Repository" dict="value
<FilesetList type="List`1" genericParam0="FileSet
<FileSet type="FileSet
<Version type="String 2.0</Version>
<Hash type="UInt32 999888777</Hash>
<FilesetStatus type="FileSetStatus" Numeric="3 Preferred</FilesetStatus>
<FilesetID type="Int32 19</FilesetID>
<RepositoryName type="String common1</RepositoryName>
</FileSet>

<FileSet type="FileSet
<Version type="String 2.1</Version>
<Hash type="UInt32 987654321</Hash>
<FilesetStatus type="FileSetStatus" Numeric="4 Preferred</FilesetStatus>
<FilesetID type="Int32 10</FilesetID>
<RepositoryName type="String common2</RepositoryName>
</FileSet>

</FilesetList>
<ReposStatus type="Int32 99</ReposStatus>
<ReposId type="Int32 2</ReposId>
<RepositoryName type="String common3</RepositoryName>
</Repository>
</Entry>
<Entry>
<String type="String" dict="key config</String>
<Repository type="Repository" dict="value
<FilesetList type="List`1" genericParam0="FileSet
<FileSet type="FileSet
<Version type="String 3.0</Version>
<Hash type="UInt32 1234512345</Hash>
<FilesetStatus type="FileSetStatus" Numeric="1 config1</FilesetStatus>
<FilesetID type="Int32 11</FilesetID>
<RepositoryName type="String software1</RepositoryName>
</FileSet>

<FileSet type="FileSet
<Version type="String 3.1</Version>
<Hash type="UInt32 9876987651</Hash>
<FilesetStatus type="FileSetStatus" Numeric="1 config2</FilesetStatus>
<FilesetID type="Int32 12</FilesetID>
<RepositoryName type="String software2</RepositoryName>
</FileSet>

</FilesetList>
<ReposStatus type="Int32 77</ReposStatus>
<ReposId type="Int32 3</ReposId>
<RepositoryName type="String config3</RepositoryName>
</Repository>
</Entry>
</RepositoryList>
<Buffer type="Byte[]"/>
</ConfigurationVersionList>[/code]
The best I can do is get portions of the outer loop to display. For example the String node displays its value, but ReposStatus only shows the indicator, not the value. A for-each loop to get FileSet doesnt display anything.
My crude, primative code looks like this:
<pre class="prettyprint <?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output method="html" indent="yes"/>

<xsl:template match="/ConfigurationVersionList
<html>
<head>
<title>Configuration Version List</title>
<link rel="stylesheet /stylesheet.css" media="all" type="text/css"/>
<style type="text/css
.style1
{
width: 152px;
}
</style>
</head>
<body>
<h1>Configuration Version List</h1>

Configuration validity: <xsl:value-of select="ConfigValidity"/>
Configuration valid Date/Time: <xsl:value-of select="ConfigValidityDT"/>
SCAC: <xsl:value-of select="Scac"/>
Configuration Version CRC: <xsl:value-of select="ConfigurationVersionCRC"/>


Repository List
<table cellpadding="0" cellspacing="0
<xsl:for-each select="RepositoryList/Entry
<tr>
<td>String: </td>
<td><xsl:value-of select="String </xsl:value-of></td>
</tr>
<tr>
<td>FileList</td>
</tr>
<xsl:for-each select="FileSetList/FileSet
<tr>
<td>Version: </td>
<td>
<xsl:value-of select="Version"/>
</td>
</tr>
<tr>
<td>Hash: </td>
<td>
<xsl:value-of select="Hash"/>
</td>
</tr>
<tr>
<td>FileSetStatus: </td>
<td>
<xsl:value-of select="FilesetStatus"/>
</td>
</tr>
<tr>
<td>FileSetID: </td>
<td>
<xsl:value-of select="FilesetID"/>
</td>
</tr>
<tr>
<td>RepositoryName: </td>
<td>
<xsl:value-of select="RepositoryName"/>
</td>
</tr>
</xsl:for-each>
<tr>
<td>ReposStatus: </td>
<td><xsl:value-of select="ReposStatus </xsl:value-of></td>
</tr>
<tr>
<td>ReposID: </td>
<td><xsl:value-of select="ReposId </xsl:value-of></td>
</tr>
<tr>
<td>RepositoryName: </td>
<td><xsl:value-of select="RepositoryName </xsl:value-of> </td>
</tr>[/code]
Any assistance and guidance will be grately appreciated.
Thanks in advance.


View the full article
 
Back
Top