Xml XSLT过滤器';s完整标记,包含子元素,但需要使用count引用筛选子标记

Xml XSLT过滤器';s完整标记,包含子元素,但需要使用count引用筛选子标记,xml,xslt,Xml,Xslt,我不熟悉XML和XSLT 目前,我正在尝试使用XSLT从XML文件中过滤一些信息 这是我的XML文件: <?xml version="1.0" encoding="UTF-8"?> <People> <Person> <required-tag1>some-information</required-tag1> <required-tag2>some-information</required-tag2

我不熟悉XML和XSLT

目前,我正在尝试使用XSLT从XML文件中过滤一些信息

这是我的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">TX</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>
    <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>CA</state>
            </licensed-states>
        </appointment-info>
    </appointments>
</Person>
<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>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>
                <state>NY</state>
                <state>CA</state>
            </licensed-states>
        </appointment-info>
        <appointment-info>
            <code>5124</code>
            <number>14920329324</number>
            <licensed-states>
                <state>NY</state>
            </licensed-states>
        </appointment-info>
    </appointments>
</Person>
</People>
这是我的XSLT:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output encoding="UTF-8" indent="yes" method="xml" version="1.0"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
    <xsl:copy>
        <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
</xsl:template>
<xsl:template match="appointment-info[licensed-states/state!=ancestor::Person/licenses/license/state]"/>
</xsl:stylesheet>
基本上,我试图做的是,如果此人在
许可证/许可证/状态中没有该状态的许可证,则仅从
约会信息/许可证状态中过滤
CA

并过滤
,如果这是唯一的状态

目前正在发生的事情是,对于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">TX</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>
  <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/>
 </Person>
 <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>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>


有人能指导我如何进行计数。

很难理解您的描述。下面的样式表适合您吗?它做了两件事:

  • 如果该人员未获得任命中所列任何州的执照,则该任命将被完全撤销
  • 如果某人在任命中列出的某些州获得执照,则保留该任命,并且该人未获得执照的州将从名单中删除
XSLT1.0

<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:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="appointment-info[not(licensed-states/state=ancestor::Person/licenses/license/state)]"/>
<xsl:template match="licensed-states/state[not(.=ancestor::Person/licenses/license/state)]"/>

</xsl:stylesheet>

很难理解您的描述。下面的样式表适合您吗?它做了两件事:

  • 如果该人员未获得任命中所列任何州的执照,则该任命将被完全撤销
  • 如果某人在任命中列出的某些州获得执照,则保留该任命,并且该人未获得执照的州将从名单中删除
XSLT1.0

<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:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="appointment-info[not(licensed-states/state=ancestor::Person/licenses/license/state)]"/>
<xsl:template match="licensed-states/state[not(.=ancestor::Person/licenses/license/state)]"/>

</xsl:stylesheet>

很难理解您的描述。下面的样式表适合您吗?它做了两件事:

  • 如果该人员未获得任命中所列任何州的执照,则该任命将被完全撤销
  • 如果某人在任命中列出的某些州获得执照,则保留该任命,并且该人未获得执照的州将从名单中删除
XSLT1.0

<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:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="appointment-info[not(licensed-states/state=ancestor::Person/licenses/license/state)]"/>
<xsl:template match="licensed-states/state[not(.=ancestor::Person/licenses/license/state)]"/>

</xsl:stylesheet>

很难理解您的描述。下面的样式表适合您吗?它做了两件事:

  • 如果该人员未获得任命中所列任何州的执照,则该任命将被完全撤销
  • 如果某人在任命中列出的某些州获得执照,则保留该任命,并且该人未获得执照的州将从名单中删除
XSLT1.0

<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:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="appointment-info[not(licensed-states/state=ancestor::Person/licenses/license/state)]"/>
<xsl:template match="licensed-states/state[not(.=ancestor::Person/licenses/license/state)]"/>

</xsl:stylesheet>


这正是我想要做的。非常感谢你帮了我,你帮了我更多的问题。我想说的是,您在XSLT方面非常有知识和专家。谢谢,这正是我想做的。非常感谢你帮了我,你帮了我更多的问题。我想说的是,您在XSLT方面非常有知识和专家。谢谢,这正是我想做的。非常感谢你帮了我,你帮了我更多的问题。我想说的是,您在XSLT方面非常有知识和专家。谢谢,这正是我想做的。非常感谢你帮了我,你帮了我更多的问题。我想说的是,您在XSLT方面非常有知识和专家。非常感谢。