使用XSLT仅显示来自xml的xml文件中不为null或零的记录
我正在使用XSLT2.0版本并检索记录表单solrXML 这是我的产品表的solr xml格式使用XSLT仅显示来自xml的xml文件中不为null或零的记录,xml,solr,xslt-2.0,Xml,Solr,Xslt 2.0,我正在使用XSLT2.0版本并检索记录表单solrXML 这是我的产品表的solr xml格式 <doc> <int name="Id">1</int> <str name="Name">$5 Virtual Gift Card</str> <float name="Price"></float> <str name="SeName">5-virtual-gift-card</str> &
<doc>
<int name="Id">1</int>
<str name="Name">$5 Virtual Gift Card</str>
<float name="Price"></float>
<str name="SeName">5-virtual-gift-card</str>
<float name="OldPrice">0.0</float>
</doc>
1.
5美元虚拟礼品卡
5-虚拟礼品卡
0
我只想在XML文件中显示那些在product表中不为null或零字段的记录
<doc>
<int name="Id">1</int>
<str name="Name">$5 Virtual Gift Card</str>
<float name="Price"></float>
<str name="SeName">5-virtual-gift-card</str>
<float name="OldPrice">0.0</float>
</doc>
请给我一些建议。您可以尝试在solr中使用xslt,如下所示:
<xsl:stylesheet version='2.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output
method="xml"
encoding="utf-8"
media-type="application/xml"
cdata-section-elements="shortdescription"
/>
<xsl:template match='/'>
<items>
<xsl:apply-templates select="response/result/doc"/>
</items>
</xsl:template>
<!-- search results xslt -->
<xsl:template match="doc">
<xsl:variable name="Price" select="format-number(*[@name = 'Price'], '#.0000###')"/>
<xsl:variable name="PriceStringToInt" select="number($Price)"/>
<!--Check some conditions like Price grater zero, price not equal to zero, price not null -->
<xsl:if test="$PriceStringToInt > 0 and $PriceStringToInt != 0 and $Price != ''>
<item>
<!--Price field-->
<price><xsl:value-of select="$Price"/></price>
</item>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
问问题时信息贫乏。您所说的非空或零字段是什么意思。你能给我举个例子吗。