我是新来的XML和XSLT,我想过滤从XML文件中的一些信息。 根据比赛的XML文件中的某些变量值。
这是我的XML文件,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<People>
<Person>
<required-tag1>some-information</required-tag1>
<required-tag2>some-information</required-tag2>
<tag3>not important info</tag3>
<tag4>not important info</tag4>
<first-name>Mike</first-name>
<last-name>Hewitt</last-name>
<licenses>
<license>
<number>938387</number>
<state xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">TX</state>
<field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Health</field>
</license>
<license>
<number>938387</number>
<state xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">IL</state>
<field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Health</field>
</license>
</licenses>
<appointments>
<appointment-info>
<code>5124</code>
<number>14920329324</number>
<licensed-states>
<state>TX</state>
</licensed-states>
</appointment-info>
</appointments>
</Person>
<Person>
<required-tag1>some-information</required-tag1>
<required-tag2>some-information</required-tag2>
<tag3>not important info</tag3>
<tag4>not important info</tag4>
<first-name>John</first-name>
<last-name>Jhonny</last-name>
<licenses>
<license>
<number>1762539</number>
<state xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">TX</state>
<field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Health</field>
</license>
<license>
<number>1762539</number>
<state xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">NY</state>
<field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Health</field>
</license>
</licenses>
<appointments>
<appointment-info>
<code>5124</code>
<number>14920329324</number>
<licensed-states>
<state>TX</state>
</licensed-states>
</appointment-info>
</appointments>
</Person>
<Person>
<required-tag1>some-information</required-tag1>
<required-tag2>some-information</required-tag2>
<tag3>not important info</tag3>
<tag4>not important info</tag4>
<first-name>Mike</first-name>
<last-name>Hewitt</last-name>
<licenses>
<license>
<number>17294083</number>
<state xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">IL</state>
<field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Health</field>
</license>
</licenses>
<appointments>
<appointment-info>
<code>5124</code>
<number>14920329324</number>
<licensed-states>
<state>IL</state>
</licensed-states>
</appointment-info>
</appointments>
</Person>
<Person>
<required-tag1>some-information</required-tag1>
<required-tag2>some-information</required-tag2>
<tag3>not important info</tag3>
<tag4>not important info</tag4>
<first-name>John</first-name>
<last-name>Jhonny</last-name>
<licenses>
<license>
<number>840790</number>
<state xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">TX</state>
<field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Health</field>
</license>
<license>
<number>840790</number>
<state xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">NY</state>
<field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Health</field>
</license>
<license>
<number>840790</number>
<state xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">CA</state>
<field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Health</field>
</license>
</licenses>
<appointments>
<appointment-info>
<code>5124</code>
<number>14920329324</number>
<licensed-states>
<state>TX</state>
<state>NY</state>
</licensed-states>
</appointment-info>
</appointments>
</Person>
</People>
我想基本上做的是,如果一个人在例如TX状态的许可。 而在该国例如TX约会信息,筛选来自许可证。 如果这是唯一的许可信息,然后筛选的人。
而新的XML应包含所需标签的信息。 而且,只有牌照,没有匹配在预约许可状态的许可。 过滤的人谁不匹配的所有许可证。
<?xml version="1.0" encoding="UTF-8"?>
<People>
<Person>
<required-tag1>some-information</required-tag1>
<required-tag2>some-information</required-tag2>
<first-name>Mike</first-name>
<last-name>Hewitt</last-name>
<licenses>
<license>
<number>938387</number>
<state xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">IL</state>
<field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Health</field>
</license>
</licenses>
</Person>
<Person>
<required-tag1>some-information</required-tag1>
<required-tag2>some-information</required-tag2>
<first-name>John</first-name>
<last-name>Jhonny</last-name>
<licenses>
<license>
<number>1762539</number>
<state xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">NY</state>
<field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Health</field>
</license>
</licenses>
</Person>
<Person>
<required-tag1>some-information</required-tag1>
<required-tag2>some-information</required-tag2>
<first-name>John</first-name>
<last-name>Jhonny</last-name>
<licenses>
<license>
<number>840790</number>
<state xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">CA</state>
<field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Health</field>
</license>
</licenses>
</Person>
</People>
如何编写XSLT来过滤这些信息。 我使用XSLT 1.0版
目前我能将此XSLT来获得所需要的标签转换。 但我不知道如何为许可证各国筛选:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="yes" method="xml"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/People">
<People>
<xsl:apply-templates select="Person"/>
</People>
</xsl:template>
<xsl:template match="Person">
<Person>
<xsl:copy-of select="required-tag1"/>
<xsl:copy-of select="required-tag2"/>
<xsl:copy-of select="first-name"/>
<xsl:copy-of select="last-name"/>
</Person>
</xsl:template>
</xsl:stylesheet>