I have an amended XSLT query thats returning everything I want but with an additional element i do not want there. how can i amend it so it get rid of the <identifier type="nt">80df0b42de8f31ac4cb7a30d325ff0c1</identifier>
line. the xml is:
我有一个修改过的XSLT查询,它会返回我想要的所有东西,但是有一个我不想要的附加元素。我该如何修改它以摆脱
<?xml version="1.0" encoding="UTF-8"?>
<CMDBTopology>
<Objects>
<CMDBSet>
<name>80df0b42de8f31ac4cb7a30d325ff0c1</name>
<CMDBObject>
<identifier type="nt">80df0b42de8f31ac4cb7a30d325ff0c1</identifier>
<Properties>
<root_class type="STRING">nt</root_class>
<host_servertype type="STRING"></host_servertype>
<host_osrelease type="STRING"></host_osrelease>
<display_label type="STRING">pharsm-s3004</display_label>
<host_osinstalltype type="STRING"></host_osinstalltype>
</Properties>
</CMDBObject>
and the xlst query that i have at the moment is `
我现在拥有的xlst查询是`
<html>
<head>
<title> title </title>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
<table width="1" border="1" >
<tr>
<td> <xsl:value-of select="display_label" /> </td>
<td> <xsl:value-of select="root_class" /> </td>
<td> <xsl:value-of select="resolver_group" /> </td>
<td> <xsl:value-of select="supported_by" /> </td>
<td> <xsl:value-of select="environment" /> </td>
<td> <xsl:value-of select="site_code" /> </td>
<td> <xsl:value-of select="sla_classification" /> </td>
<td> <xsl:value-of select="datacenter" /> </td>
</tr>
</table>
`
`
1 个解决方案
#1
1
It's hard to give a precise answer, not knowing exactly what you want your output to look like, but your main problem is that you have a template matching CMDBRelation
in your XSLT, like so...
很难给出一个精确的答案,不知道你想要输出的确切内容,但你的主要问题是你的XSLT中有一个匹配CMDBRelation的模板,就像这样......
<xsl:template match="CMDBRelation" >
But there is no such CMDBRelation
element in your XML! This means this template will never get called. This means, when you do <xsl:apply-templates />
in your first template, then XSLT's "built-in templates" are being used. These effectively iterate over all nodes in the XML, outputting text nodes where they find them, which is why you get all the text printing out and no table formatting.
但是XML中没有这样的CMDBRelation元素!这意味着永远不会调用此模板。这意味着,当您在第一个模板中执行
I suspect your template actually needs to match CMDBSet
我怀疑你的模板实际上需要匹配CMDBSet
<xsl:template match="CMDBRelation" >
You also seem to be referring to To
and From
elements in your xsl:for-each
statements, and as before, such elements don't exist in your XML.
您似乎也在引用xsl:for-each语句中的To和From元素,并且像以前一样,XML中不存在这些元素。
<xsl:for-each select="To/CMDBObject/Properties">
It is possible you need to combine the two statements into one, like this
您可能需要将两个语句合并为一个,如下所示
<xsl:for-each select="CMDBObject/Properties">
Here is some amended XSLT to start you off, that does produce a table and doesn't output any identifier
element.
这里有一些修改过的XSLT启动你,它确实生成一个表,并且不输出任何标识符元素。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title> title </title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="CMDBSet">
<table width="1" border="1">
<xsl:for-each select="CMDBObject/Properties">
<tr>
<td><xsl:value-of select="display_label"/></td>
<td><xsl:value-of select="root_class"/></td>
<td><xsl:value-of select="host_servertype"/></td>
<td><xsl:value-of select="host_osrelease"/></td>
<td><xsl:value-of select="host_osinstall"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
#1
1
It's hard to give a precise answer, not knowing exactly what you want your output to look like, but your main problem is that you have a template matching CMDBRelation
in your XSLT, like so...
很难给出一个精确的答案,不知道你想要输出的确切内容,但你的主要问题是你的XSLT中有一个匹配CMDBRelation的模板,就像这样......
<xsl:template match="CMDBRelation" >
But there is no such CMDBRelation
element in your XML! This means this template will never get called. This means, when you do <xsl:apply-templates />
in your first template, then XSLT's "built-in templates" are being used. These effectively iterate over all nodes in the XML, outputting text nodes where they find them, which is why you get all the text printing out and no table formatting.
但是XML中没有这样的CMDBRelation元素!这意味着永远不会调用此模板。这意味着,当您在第一个模板中执行
I suspect your template actually needs to match CMDBSet
我怀疑你的模板实际上需要匹配CMDBSet
<xsl:template match="CMDBRelation" >
You also seem to be referring to To
and From
elements in your xsl:for-each
statements, and as before, such elements don't exist in your XML.
您似乎也在引用xsl:for-each语句中的To和From元素,并且像以前一样,XML中不存在这些元素。
<xsl:for-each select="To/CMDBObject/Properties">
It is possible you need to combine the two statements into one, like this
您可能需要将两个语句合并为一个,如下所示
<xsl:for-each select="CMDBObject/Properties">
Here is some amended XSLT to start you off, that does produce a table and doesn't output any identifier
element.
这里有一些修改过的XSLT启动你,它确实生成一个表,并且不输出任何标识符元素。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<title> title </title>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="CMDBSet">
<table width="1" border="1">
<xsl:for-each select="CMDBObject/Properties">
<tr>
<td><xsl:value-of select="display_label"/></td>
<td><xsl:value-of select="root_class"/></td>
<td><xsl:value-of select="host_servertype"/></td>
<td><xsl:value-of select="host_osrelease"/></td>
<td><xsl:value-of select="host_osinstall"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>