显示除xslt外的所有节点

问题描述:

我想显示除两个之外的所有节点及其值。例如,显示所有除“类型”和“价格”显示除xslt外的所有节点

<xsl:for-each select="market/device"> 
<!-- ... --> 
    <xsl:for-each select="*[local-name()!='type']"> <!-- <<< here --> 
    <li><xsl:value-of select="local-name()"/></li> 
    <li><xsl:value-of select="."/></li> 
    </xsl:for-each> 
<!-- ... --> 
</xsl:for-each> 
+0

你要什么我们做什么?请参阅如何问问节:http://*.com/help/how-to-ask。你的问题很不清楚。 – cybermonkey

+0

你知道XPath中的'not'函数(!),是吗? –

由于您没有提供输入,我刚刚成立下面的XML作为例子:

输入XML:

<?xml version="1.0" encoding="UTF-8"?> 
<markets> 
    <market> 
    <device> 
     <type>type value</type> 
     <price>price value</price> 
     <nottype>nottype value</nottype> 
     <notprice>notprice value</notprice> 
     <else>else value</else> 
    </device> 
    </market> 
</markets> 

当下面的XSLT施加:

<?xml version="1.0" encoding="UTF-8" ?> 
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> 
<xsl:output method="html" doctype-public="XSLT-compat" 
    omit-xml-declaration="yes" encoding="UTF-8" indent="yes" /> 
<xsl:template match="/"> 
    <hmtl> 
    <head> 

    </head> 
    <xsl:apply-templates/> 
    </hmtl> 
</xsl:template> 
<xsl:template match="markets"> 
<ul> 
<xsl:for-each select="market/device"> 
    <xsl:for-each select="*[not((local-name() = 'type') or (local-name() = 'price'))]"> 
    <li><xsl:value-of select="local-name()"/></li> 
    <li><xsl:value-of select="."/></li> 
    </xsl:for-each> 
</xsl:for-each> 
</ul> 
</xsl:template> 
</xsl:transform> 

如下输出产生(ONY相关部分发布):

<ul> 
    <li>nottype</li> 
    <li>nottype value</li> 
    <li>notprice</li> 
    <li>notprice value</li> 
    <li>else</li> 
    <li>else value</li> 
</ul> 

参考:https://developer.mozilla.org/en-US/docs/Web/XPath/Functions/not