.xml如何使用XSLT 样式表。结果将是一个具有以下结构的 XML 文件( item.xml) 其中 ocshelf="yes" 和 type= "cosmetic"
产品.xml------------------------
<products>
<product onshelf=“yes” condition=“ok”>
<type>cosmetic</type>
<price>680</price>
<address>
<streetNo>1</streetNo>
<street>Jefer Street</street>
<suburb>Melbourne</suburb>
</address>
</product>
<product onshelf=“yes” condition=“ok”>
<type>noncosmetic</type>
<price>600</price>
<address>
<streetNo>2</streetNo>
<street>Colo Street</street>
<suburb>Melbourne</suburb>
</address>
</product>
</products>
项目.xml---------------------------------
<products>
<product condition=“ok”>
<type>cosmetic</type>
<price>680</price>
<address>1 Jefer Street , Melbourne </address>
</product>
</products>
你可以尝试这样的事情:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="/">
<products>
<xsl:apply-templates
select="/products/product[@onshelf='yes' and type='cosmetic']"/>
</products>
</xsl:template>
<xsl:template match="product">
<product condition="{@condition}">
<xsl:apply-templates />
</product>
</xsl:template>
<xsl:template match="address">
<address>
<xsl:value-of select="concat(streetNo, ' ', street, ', ', suburb)" />
</address>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
如果您不熟悉 XSLT,我建议您查看此线程以获取教程建议:https://stackoverflow.com/questions/1858345/xsltwhich-is-the-best-tutorial-you-would-like-to-recommend。