XSL select pattern for root element with schema

D

David Nedrow

[sorry for the possible dupe]

OK, I have a problem which I'm guessing is simply my inability to
figure out a select pattern in XSL.


I have an XML file similar to the following:


<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="vmv.xsl"?>
<ruleset xmlns="https://foo.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://foo.com vmv.xsd">
<rule>
<name>FIND_SGID_LOCAL</name>
<desc>Examine the sgid files.</desc>
<vdesc>Test</vdesc>
<expected/>
<code/>
<command>
<command>ls</command>
<parse>tes</parse>
<desc>test</desc>
<vdesc>test</vdesc>
</command>
<os name="linux" enabled="true"/>
</rule>
</ruleset>


I wold like to be able to provide a "pretty" version via the vmv.xsl
file ref'd in the markup above.


Here is a simplified version of the XSL file:


<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html>
<body>
<h2>Audit Rules</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Name</th>
<th align="left">Description</th>
</tr>
<xsl:for-each select="ruleset/rule">
<tr>
<td>
<xsl:value-of select="name"/>
</td>
<td>
<xsl:value-of select="desc"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>




My problem is that the select in the <xsl:for-each/> statement does not
match the root node, presumably because of the inclusion on the XML file
of the schema in the <ruleset/> attributes.


If I delete the schema info from <ruleset/> in the XML file, then the
table I generate in the XSL file works properly. THat's why I'm sure
I've just got to figure out the correct select pattern for the
<xsl:for-each/> statement.


Any suggestions out there?


Thanks in advance,


David
 
M

Martin Honnen

David Nedrow wrote:

I have an XML file similar to the following:


<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="vmv.xsl"?>
<ruleset xmlns="https://foo.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://foo.com vmv.xsd">
<rule>
<name>FIND_SGID_LOCAL</name>
<desc>Examine the sgid files.</desc>
<vdesc>Test</vdesc>
<expected/>
<code/>
<command>
<command>ls</command>
<parse>tes</parse>
<desc>test</desc>
<vdesc>test</vdesc>
</command>
<os name="linux" enabled="true"/>
</rule>
</ruleset>


I wold like to be able to provide a "pretty" version via the vmv.xsl
file ref'd in the markup above.


Here is a simplified version of the XSL file:


<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html>
<body>
<h2>Audit Rules</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Name</th>
<th align="left">Description</th>
</tr>
<xsl:for-each select="ruleset/rule">
<tr>
<td>
<xsl:value-of select="name"/>
</td>
<td>
<xsl:value-of select="desc"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>




My problem is that the select in the <xsl:for-each/> statement does not
match the root node, presumably because of the inclusion on the XML file
of the schema in the <ruleset/> attributes.

Your elements in the XML file are in the namespace https://foo.com,
declare a prefix for that namespace in the XSLT stylesheet e.g.
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:foo="https://foo.com">
and then use that prefix in your pattern/XPath expressions e.g.
<xsl:for-each select="foo:ruleset/foo:rule">
<xsl:value-of select="foo:name" />
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,089
Latest member
Ketologenic

Latest Threads

Top