XSLT中有没有一种方法可以基于单个节点创建一段巨大的XML
我有一个如下所示的XML:XSLT中有没有一种方法可以基于单个节点创建一段巨大的XML,xml,xslt,Xml,Xslt,我有一个如下所示的XML: <xml> <agreement> <country>Canada</country> <state>Ontario</state> <person> <name>Mark</name> </person> </ag
<xml>
<agreement>
<country>Canada</country>
<state>Ontario</state>
<person>
<name>Mark</name>
</person>
</agreement>
<agreement>
<country>USA</country>
<state>Alabama</state>
<person>
<name>John</name>
</person>
</agreement>
<agreement>
<country>United Kingdom</country>
<state></state>
<person>
<name>Eric</name>
</person>
</agreement>
</xml>
加拿大
安大略
做记号
美国
阿拉巴马州
约翰
大不列颠联合王国
埃里克
我现在需要生成一个xml,当国家是加拿大时,它只显示协议下的所有内容。我有没有办法在XSLT中实现这一点
输出:
<xml>
<agreement>
<country>Canada</country>
<state>Ontario</state>
<person>
<name>Mark</name>
</person>
</agreement>
</xml>
加拿大
安大略
做记号
您可以尝试以下XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xml>
<xsl:apply-templates select="xml/agreement[country='Canada']"/>
</xml>
</xsl:template>
<xsl:template match="agreement">
<xsl:copy-of select="."></xsl:copy-of>
</xsl:template>
</xsl:stylesheet>
或稍后:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/xml">
<xsl:copy>
<xsl:copy-of select="agreement[country='Canada']"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
这是否回答了您的问题?