Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xslt 如何跨两个模板应用筛选器_Xslt_Xpath - Fatal编程技术网

Xslt 如何跨两个模板应用筛选器

Xslt 如何跨两个模板应用筛选器,xslt,xpath,Xslt,Xpath,在另一个线程中,另一个开发人员帮助我提供了下面令人敬畏的答案 基本上有两个模板用于检索我需要在表中显示的所有数据 我现在的问题是,我现在如何应用一个过滤器来过滤这两个模板?我可以在xsl:template match=子组中成功地使用select=@Name[contains.,NameIWant1]的xsl:value,但我不知道如何将其应用于xsl:template match=数据。我试着用各种各样的命名方法,但都没有用 提前感谢你们对我学习XSLT的巨大帮助!!千克 示例XML <

在另一个线程中,另一个开发人员帮助我提供了下面令人敬畏的答案

基本上有两个模板用于检索我需要在表中显示的所有数据

我现在的问题是,我现在如何应用一个过滤器来过滤这两个模板?我可以在xsl:template match=子组中成功地使用select=@Name[contains.,NameIWant1]的xsl:value,但我不知道如何将其应用于xsl:template match=数据。我试着用各种各样的命名方法,但都没有用

提前感谢你们对我学习XSLT的巨大帮助!!千克

示例XML

<?xml-stylesheet type="text/xsl" href="Sample.xsl"?>
<DataView Client="Client1" ID="1000" TimeStamp="12/7/2011 5:35:09 PM">
<Group ID="5000" Name="GroupName1">
<SubGroup ID="7000" Order="0" Name="NameIWant1">
<Data ID="1" Name="DataName1" Order="0">1</Data>
<Data ID="2" Name="DataName2" Order="0">2</Data>
<Data ID="3" Name="DataName3" Order="0">3</Data>
<Data ID="12" Name="DataName4" Order="0">4</Data>
</SubGroup>
<SubGroup ID="8000" Order="0" Name="NameIWant2">
<Data ID="1" Name="DataName1" Order="0">6</Data>
<Data ID="2" Name="DataName2" Order="0">7</Data>
<Data ID="3" Name="DataName3" Order="0">8</Data>
<Data ID="12" Name="DataName4" Order="0">9</Data>
</SubGroup>
</Group>
</DataView> 
我明白了

____________________________
NameIWant1 | 1 | 2 | 3 | 4 |
           | 6 | 7 | 8 | 9 |
我想

____________________________
NameIWant1 | 1 | 2 | 3 | 4 |

按名称筛选子组的最简单方法是将表达式移动到匹配模式中,如下所示:

<xsl:template match="SubGroup[contains(@Name, 'NameIWant1')]">
    <tr>
        <td><xsl:value-of select="@Name"/></td>
        <xsl:apply-templates/>
    </tr>
</xsl:template>
完整样式表:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="/">
        <html>
            <body>
                <h2>My Data</h2>
                <table border="1">
                    <tr bgcolor="#9acd32">
                        <th>Subgroup</th>
                        <th>DataName1</th>
                        <th>DataName2</th>
                        <th>DataName3</th>
                        <th>DataName4</th>
                    </tr>
                    <xsl:apply-templates/>
                </table>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="SubGroup[contains(@Name, 'NameIWant1')]">
        <tr>
            <td><xsl:value-of select="@Name"/></td>
            <xsl:apply-templates/>
        </tr>
    </xsl:template>
    <xsl:template match="SubGroup"/>
    <xsl:template match="Data">
        <td><xsl:apply-templates/></td>
    </xsl:template>
</xsl:stylesheet>

您是否试图根据Name属性筛选要显示的子组?是的,我想我理解SubGroup中的Name属性。看看我的答案。如果这不是你想要做的,请告诉我,我会解决它。这非常有效。再次感谢lwburk的专业知识。我已经订购了我的入门XSLT书籍LOL
<xsl:template match="SubGroup"/>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="/">
        <html>
            <body>
                <h2>My Data</h2>
                <table border="1">
                    <tr bgcolor="#9acd32">
                        <th>Subgroup</th>
                        <th>DataName1</th>
                        <th>DataName2</th>
                        <th>DataName3</th>
                        <th>DataName4</th>
                    </tr>
                    <xsl:apply-templates/>
                </table>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="SubGroup[contains(@Name, 'NameIWant1')]">
        <tr>
            <td><xsl:value-of select="@Name"/></td>
            <xsl:apply-templates/>
        </tr>
    </xsl:template>
    <xsl:template match="SubGroup"/>
    <xsl:template match="Data">
        <td><xsl:apply-templates/></td>
    </xsl:template>
</xsl:stylesheet>