Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/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
Xml 为什么<;xsl:apply templates select="//z:row";模式=";项目“/&燃气轮机;返回空,但<;xsl:select的副本="//z:row"/&燃气轮机;返回一个节点集?_Xml_Xslt - Fatal编程技术网

Xml 为什么<;xsl:apply templates select="//z:row";模式=";项目“/&燃气轮机;返回空,但<;xsl:select的副本="//z:row"/&燃气轮机;返回一个节点集?

Xml 为什么<;xsl:apply templates select="//z:row";模式=";项目“/&燃气轮机;返回空,但<;xsl:select的副本="//z:row"/&燃气轮机;返回一个节点集?,xml,xslt,Xml,Xslt,输入XML 输入XML具有嵌套的NewDataSet/Contracts节点,因为它是由一系列“递归”转换生成的。这就是我必须处理的问题 <NewDataSet> <Contracts> <NewDataSet> <Contracts> <NewDataSet> <Contracts>

输入XML 输入XML具有嵌套的NewDataSet/Contracts节点,因为它是由一系列“递归”转换生成的。这就是我必须处理的问题

<NewDataSet>
    <Contracts>
        <NewDataSet>
            <Contracts>
                <NewDataSet>
                    <Contracts>
                        <NewDataSet>
                            <Contracts>
                                <listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns="http://schemas.microsoft.com/sharepoint/soap/">
                                    <rs:data xmlns:rs="urn:schemas-microsoft-com:rowset" ItemCount="6">
                                        <z:row xmlns:z="#RowsetSchema" ows_BPID="VCT-00139" ows_Title="Contract - Joe Owner Jane Co-Owner" ows_PerformanceStart="2021-07-05T20:09:07Z" ows_PerformanceEnd="2023-03-27T20:09:07Z"/>
                                        <z:row xmlns:z="#RowsetSchema" ows_BPID="VCT-00138" ows_Title="Contract - Jane Owner Joe Co-Owner" ows_PerformanceStart="2021-05-06T20:07:57Z" ows_PerformanceEnd="2022-04-01T20:07:57Z"/>
                                    </rs:data>
                                </listitems>
                            </Contracts>
                        </NewDataSet>
                    </Contracts>
                </NewDataSet>
            </Contracts>
        </NewDataSet>
    </Contracts>
</NewDataSet>

样式表#1

<xsl:stylesheet version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:date="http://exslt.org/dates-and-times" xmlns:cw="http://schemas.microsoft.com/sharepoint/soap/" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" >
    <xsl:output omit-xml-declaration="yes"/>
    <xsl:template match="/">
        <Items xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
            <xsl:apply-templates select="//z:row" mode="Items" />
        </Items>
    </xsl:template> 

    <xsl:template match="*" mode="Items">
        <Item>
            <xsl:attribute name='ows_Title' >
                <xsl:value-of select="@ows_Title"/>
            </xsl:attribute>
        </Item>     
    </xsl:template> 
</xsl:stylesheet>

样式表#2

<xsl:stylesheet version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:date="http://exslt.org/dates-and-times" xmlns:cw="http://schemas.microsoft.com/sharepoint/soap/" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" >
    <xsl:output omit-xml-declaration="yes"/>
    <xsl:template match="/">
        <Items xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
            <xsl:copy-of select="//z:row" />
        </Items>
    </xsl:template> 

    <xsl:template match="*" mode="Items">
        <Item>
            <xsl:attribute name='ows_Title' >
                <xsl:value-of select="@ows_Title"/>
            </xsl:attribute>
        </Item>     
    </xsl:template> 
</xsl:stylesheet>   

样式表#3

<xsl:stylesheet version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:date="http://exslt.org/dates-and-times" xmlns:cw="http://schemas.microsoft.com/sharepoint/soap/" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" >
    <xsl:output omit-xml-declaration="yes"/>
    <xsl:template match="/">
        <Items xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
            <xsl:apply-templates select="//z:row" mode="Items" />
            <xsl:copy-of select="//z:row" />
        </Items>
    </xsl:template> 

    <xsl:template match="*" mode="Items">
        <Item>
            <xsl:attribute name='ows_Title' >
                <xsl:value-of select="@ows_Title"/>
            </xsl:attribute>
        </Item>     
    </xsl:template> 
</xsl:stylesheet>   

当我应用样式表#1时,我得到一个空响应

当我应用样式表#2时,我得到


当我应用样式表#3时,我得到


但是,我真正想要的是

<Items>
    <Item ows_Title="Contract - Joe Owner Jane Co-Owner" />
    <Item ows_Title="Contract - Jane Owner Joe Co-Owner" />
</Items>

我不了解足够的XML/XSLT来理解这种行为。为什么应用模板不返回任何内容,就好像select=“//z:row”为空,而副本返回的内容正是我所期望的那样

我怎样才能得到我想要的结果


非常感谢您的帮助。

“当我应用样式表#1时,我得到了一个空的响应。”我看到了一个不同的结果:是的,我看到了。您得到了预期的结果,这对我的XSLT来说是个好消息,但对于实际解决我的问题来说却很糟糕,因为没有人能够复制它。smh。ThanksDouble检查所使用的任何名称空间、输入和XSLT之间的任何空白或拼写差异都可能解释应用模板不选择任何内容的原因。另外,您使用哪个XSLT处理器?您是否尝试通过不同的处理器运行失败的代码?我希望所有这些样式表都会生成一个包含多个名称空间声明的
Items
元素。如果没有,那么您的XSLT处理器就有一些非常奇怪的地方。使用Saxon 9.1.J并应用您的第一次转换,我得到了您想要的结果。很明显,您使用的是有缺陷的XSLT处理器。即使使用兼容的XSLT1.0处理器,如MSXML 4.0或Saxon 6.5.3,也会产生相同的预期结果。
<Items>
    <Item ows_Title="Contract - Joe Owner Jane Co-Owner" />
    <Item ows_Title="Contract - Jane Owner Joe Co-Owner" />
    <z:row xmlns:z="#RowsetSchema" ows_BPID="VCT-00139" ows_Title="Contract - Joe Owner Jane Co-Owner" ows_PerformanceStart="2021-07-05T20:09:07Z" ows_PerformanceEnd="2023-03-27T20:09:07Z"/>
    <z:row xmlns:z="#RowsetSchema" ows_BPID="VCT-00138" ows_Title="Contract - Jane Owner Joe Co-Owner" ows_PerformanceStart="2021-05-06T20:07:57Z" ows_PerformanceEnd="2022-04-01T20:07:57Z"/>
</Items>
<Items>
    <Item ows_Title="Contract - Joe Owner Jane Co-Owner" />
    <Item ows_Title="Contract - Jane Owner Joe Co-Owner" />
</Items>