XSLT 前同级限制和解决方法

发布于 2024-11-01 03:41:20 字数 4370 浏览 1 评论 0原文

我对前兄弟姐妹有问题。这真的有效吗?

XSL 看起来像这样

<stored-procedure id="search-algorithm-parent-child">
    <xsl:stylesheet version="1.0" xmlns:spbc="urn:lsapps.spbcontext" xmlns:user="http://www.lodestarcorp.com" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
        <xsl:output omit-xml-declaration="yes"/>
        <xsl:template match="node()|/|@*">
            <query name="CMNUALGPARENTCHILD">
                <sql>
                    SELECT 
                      parent.UIDALGLIBPARENTDTL as UIDPARENT,
                      parent.PARENTCHANNELID as VMCHANNELNUMBER, 
                      parent.UOMCODE as UOM, 
                      child.CHILDDCFLOW AS DCFLOW,
                    FROM
                      ##Q.NUALGLIBPARENTDTL parent,
                      ##Q.NUALGLIBCHILDDTL child 
                    WHERE 
                      child.UIDALGLIBPARENTDTL = parent.UIDALGLIBPARENTDTL
                      AND parent.UIDALGLIBRARY = '<xsl:value-of select="@UIDALGLIBRARY"/>'
                      ORDER BY UIDPARENT
                </sql>
            </query>
        </xsl:template>
    </xsl:stylesheet>
</stored-procedure>

当我将上面的 XSL 传递给我的 asp 中的 LsdbCommand 时,我不知道 XML 是什么样子像这样

var xmlTable5 = LsdbCommand("LSDB.search-algorithm-parent-child", PrefixParams1.valueOf());

我假设 XML 数据将是这样的(按 UIDPARENT 排序):

<CMNUALGPARENTCHILD>
  <someNode>
    <UIDPARENT>21</UIDPARENT>
    <VMCHANNELNUMBER>123</VMCHANNELNUMBER>
    <UOM>5<UOM>
    <DCFLOW>R<DCFLOW>
  </someNode>
  <someNode>
    <UIDPARENT>21</UIDPARENT>
    <VMCHANNELNUMBER>123</VMCHANNELNUMBER>
    <UOM>5<UOM>
    <DCFLOW>R<DCFLOW>
  </someNode>
  ...
</CMNUALGPARENTCHILD>

现在,我关心的是 UIDPARENT .. 我确信结果将具有以下 UIDPARENT .. (按顺序)

21
21
21
81
81
81

现在,在 asp 中,我将其称为

tTable5 = ProcessXsl(xmlTable5, XmlFreeFile("../zAlgorithmLibrary/AlgorithmParentChild.xslt"));

其中AlgorithmParentChild.xslt 只是

<x:stylesheet version="1.0"
  xmlns:x="http://www.w3.org/1999/XSL/Transform"
  xmlns:i="urn:ls-i18n-formatter"
  xmlns:ms="urn:schemas-microsoft-com:xslt"
  xmlns:user="http://www.lodestarcorp.com/user"
  exclude-result-prefixes="x i ms user">

<x:param name="Portal">N</x:param>
<x:param name="Include">ALL</x:param>
<x:param name="OrderParams"></x:param>
<x:param name="FromParam"></x:param>
<x:param name="ROWPERPAGE">25</x:param>
<x:param name="AllowEdit"></x:param>

<x:output method="html" version="1.0" encoding="UTF-8" indent="yes"/> 
<x:template match="/">
  <table class="FormTable">
    <x:for-each select="//CMNUALGPARENTCHILD">
      <tr>
        <td>current <x:value-of select="@UIDPARENT"/></td>
        <td>previous <x:value-of select="preceding-sibling::node()/@UIDPARENT"/></td> 
        <td>next <x:value-of select="following-sibling::node()/@UIDPARENT"/></td>
      </tr>
    </x:for-each>
  </table>
</x:template>

<x:include href="../controls/MultiSortImages.xslt"/>
<x:include href="../controls/LockedColumns.xslt"/>
</x:stylesheet>

主表,看起来像这样

current 21 previous  next 21 
current 21 previous 21 next 21 
current 21 previous 21 next 81 
current 81 previous 21 next 81 
current 81 previous 21 next 81 
current 81 previous 21 next  

。前三个结果似乎是正确的..但是为什么前面的元素在第三次迭代后失败了?它应该返回以下内容:

current 21 previous  next 21 
current 21 previous 21 next 21 
current 21 previous 21 next 81 
current 81 previous 21 next 81 
current 81 previous 81 next 81 
current 81 previous 81 next  

follow-sibling 工作正常.. previous-sibling 是否有任何已知的限制?你能建议任何解决方法吗?

请注意,我还尝试在前一个兄弟姐妹上附加 [position=1][position()] 或简单地 [1]:: node()/@UIDPARENT 但它仍然有相同的结果..

请理解我是 ASP、XSLT、XSL 的新手..并且我只放置了代码片段而不是整个代码..

我只是想了解previous-sibling 是如何工作的..它的语法,关于它的一切..

I'm having problem with preceding-sibling. Is this really working?

XSL looks something like this:

<stored-procedure id="search-algorithm-parent-child">
    <xsl:stylesheet version="1.0" xmlns:spbc="urn:lsapps.spbcontext" xmlns:user="http://www.lodestarcorp.com" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
        <xsl:output omit-xml-declaration="yes"/>
        <xsl:template match="node()|/|@*">
            <query name="CMNUALGPARENTCHILD">
                <sql>
                    SELECT 
                      parent.UIDALGLIBPARENTDTL as UIDPARENT,
                      parent.PARENTCHANNELID as VMCHANNELNUMBER, 
                      parent.UOMCODE as UOM, 
                      child.CHILDDCFLOW AS DCFLOW,
                    FROM
                      ##Q.NUALGLIBPARENTDTL parent,
                      ##Q.NUALGLIBCHILDDTL child 
                    WHERE 
                      child.UIDALGLIBPARENTDTL = parent.UIDALGLIBPARENTDTL
                      AND parent.UIDALGLIBRARY = '<xsl:value-of select="@UIDALGLIBRARY"/>'
                      ORDER BY UIDPARENT
                </sql>
            </query>
        </xsl:template>
    </xsl:stylesheet>
</stored-procedure>

I dont't know how XML looks like when I pass above XSL to LsdbCommand in my asp like this:

var xmlTable5 = LsdbCommand("LSDB.search-algorithm-parent-child", PrefixParams1.valueOf());

I'm assuming that XML data will be something like this (ordered by UIDPARENT):

<CMNUALGPARENTCHILD>
  <someNode>
    <UIDPARENT>21</UIDPARENT>
    <VMCHANNELNUMBER>123</VMCHANNELNUMBER>
    <UOM>5<UOM>
    <DCFLOW>R<DCFLOW>
  </someNode>
  <someNode>
    <UIDPARENT>21</UIDPARENT>
    <VMCHANNELNUMBER>123</VMCHANNELNUMBER>
    <UOM>5<UOM>
    <DCFLOW>R<DCFLOW>
  </someNode>
  ...
</CMNUALGPARENTCHILD>

For now, my concern is the UIDPARENT.. What I'm sure of is that result would have the following UIDPARENT..(in order)

21
21
21
81
81
81

Now, in the asp, I call this

tTable5 = ProcessXsl(xmlTable5, XmlFreeFile("../zAlgorithmLibrary/AlgorithmParentChild.xslt"));

where AlgorithmParentChild.xslt is simply

<x:stylesheet version="1.0"
  xmlns:x="http://www.w3.org/1999/XSL/Transform"
  xmlns:i="urn:ls-i18n-formatter"
  xmlns:ms="urn:schemas-microsoft-com:xslt"
  xmlns:user="http://www.lodestarcorp.com/user"
  exclude-result-prefixes="x i ms user">

<x:param name="Portal">N</x:param>
<x:param name="Include">ALL</x:param>
<x:param name="OrderParams"></x:param>
<x:param name="FromParam"></x:param>
<x:param name="ROWPERPAGE">25</x:param>
<x:param name="AllowEdit"></x:param>

<x:output method="html" version="1.0" encoding="UTF-8" indent="yes"/> 
<x:template match="/">
  <table class="FormTable">
    <x:for-each select="//CMNUALGPARENTCHILD">
      <tr>
        <td>current <x:value-of select="@UIDPARENT"/></td>
        <td>previous <x:value-of select="preceding-sibling::node()/@UIDPARENT"/></td> 
        <td>next <x:value-of select="following-sibling::node()/@UIDPARENT"/></td>
      </tr>
    </x:for-each>
  </table>
</x:template>

<x:include href="../controls/MultiSortImages.xslt"/>
<x:include href="../controls/LockedColumns.xslt"/>
</x:stylesheet>

main table looks like this

current 21 previous  next 21 
current 21 previous 21 next 21 
current 21 previous 21 next 81 
current 81 previous 21 next 81 
current 81 previous 21 next 81 
current 81 previous 21 next  

It seems correct on the first three result.. but how come preceding-element failed after the third iteration? It should return the following:

current 21 previous  next 21 
current 21 previous 21 next 21 
current 21 previous 21 next 81 
current 81 previous 21 next 81 
current 81 previous 81 next 81 
current 81 previous 81 next  

following-sibling works fine.. are there any known limitations of preceding-sibling? and can you suggest any workaround?

Note that I have also tried appending [position=1] or [position()] or simply [1] on preceding-sibling::node()/@UIDPARENT but it still have the same result..

Please understand that I am new to ASP, XSLT, XSL.. and that I have only put snippets of code and not the entire code..

I just want to understand how preceding-sibling works.. its syntax, everything about it..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盛夏尉蓝 2024-11-08 03:41:20

正如 W3C 规范中所述:

前同级轴包含上下文节点的所有前同级

但它没有说的是它的工作原理相反!您需要将 [position()=1] 谓词添加到 XPath 选择的末尾,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<x:stylesheet version="1.0"
  xmlns:x="http://www.w3.org/1999/XSL/Transform"
  exclude-result-prefixes="x">
<x:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>   
<x:template match="CMNUALGPARENTCHILD">
  <table>
    <x:for-each select="UIDPARENT">
      <tr>
        <td>current <x:value-of select="."/></td>
        <td>previous <x:value-of select="preceding-sibling::UIDPARENT[position()=1]"/></td>
        <td>next <x:value-of select="following-sibling::UIDPARENT[position()=1]"/></td>
      </tr>
    </x:for-each>
 </table>
</x:template>
</x:stylesheet>

我无法让问题中的 XSL 正常工作。但这对我来说适用于你问题中的 XML。

编辑:从原始问题添加XML以供参考

<CMNUALGPARENTCHILD>
    <UIDPARENT>21</UIDPARENT>
    <UIDPARENT>21</UIDPARENT>
    <UIDPARENT>21</UIDPARENT>
    <UIDPARENT>81</UIDPARENT>
    <UIDPARENT>81</UIDPARENT>
    <UIDPARENT>81</UIDPARENT>
</CMNUALGPARENTCHILD>

As described in the W3C specification:

the preceding-sibling axis contains all the preceding siblings of the context node

What it does not say is that it works in reverse! You need to add a [position()=1] predicate to the end of your XPath select like this:

<?xml version="1.0" encoding="UTF-8"?>
<x:stylesheet version="1.0"
  xmlns:x="http://www.w3.org/1999/XSL/Transform"
  exclude-result-prefixes="x">
<x:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>   
<x:template match="CMNUALGPARENTCHILD">
  <table>
    <x:for-each select="UIDPARENT">
      <tr>
        <td>current <x:value-of select="."/></td>
        <td>previous <x:value-of select="preceding-sibling::UIDPARENT[position()=1]"/></td>
        <td>next <x:value-of select="following-sibling::UIDPARENT[position()=1]"/></td>
      </tr>
    </x:for-each>
 </table>
</x:template>
</x:stylesheet>

I couldn't get the XSL in your question to work. But this works with the XML in your question for me.

Edit: Adding in XML from original question for reference

<CMNUALGPARENTCHILD>
    <UIDPARENT>21</UIDPARENT>
    <UIDPARENT>21</UIDPARENT>
    <UIDPARENT>21</UIDPARENT>
    <UIDPARENT>81</UIDPARENT>
    <UIDPARENT>81</UIDPARENT>
    <UIDPARENT>81</UIDPARENT>
</CMNUALGPARENTCHILD>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文