xslt返回以下同级的选择

xslt返回以下同级的选择,xslt,Xslt,我选择了一些XML(已编辑) 我希望能够在下一个lcn之前从给定lcn获取以下所有节点 如果我从lcn='005417714'开始,我知道有以下4个节点 但是当我尝试做这样的事情时 <xsl:for-each select="/items/item[@lcn='005417714']/following-sibling::*"> 我有下面所有的兄弟姐妹。如何在下一个非空lcn属性之前获取以下所有同级?那么,只检索以下4个兄弟姐妹?感谢使用xslt-1.0,您可以尝试以下类似

我选择了一些XML(已编辑)


我希望能够在下一个lcn之前从给定lcn获取以下所有节点

如果我从lcn='005417714'开始,我知道有以下4个节点

但是当我尝试做这样的事情时

<xsl:for-each select="/items/item[@lcn='005417714']/following-sibling::*">


我有下面所有的兄弟姐妹。如何在下一个非空lcn属性之前获取以下所有同级?那么,只检索以下4个兄弟姐妹?感谢使用xslt-1.0,您可以尝试以下类似基于密钥的解决方案: (只是为了说明它是如何工作的)


将生成以下输出:

<items>
  <lcn lcn="005417713">
    <item id="00100537" label="A/137i r" lcn="005417713" notes="A/137-160"/>
    <item id="00100538" label="A/137i v" lcn="" notes=""/>
    <item id="00100539" label="A/137ii r" lcn="" notes=""/>
    <item id="00100540" label="A/137ii v" lcn="" notes=""/>
    <item id="00100678" label="A/159iii v" lcn="" notes=""/>
    <item id="00100679" label="A/159iv r" lcn="" notes=""/>
    <item id="00100680" label="A/159iv v" lcn="" notes=""/>
    <item id="00100681" label="A/160i r" lcn="" notes=""/>
    <item id="00100682" label="A/160i v" lcn="" notes=""/>
    <item id="00100683" label="A/160ii r" lcn="" notes=""/>
    <item id="00100684" label="A/160ii v" lcn="" notes=""/>
    <item id="00100685" label="A/160iii r" lcn="" notes=""/>
    <item id="00100686" label="A/160iii v" lcn="" notes=""/>
  </lcn>
  <lcn lcn="005417714">
    <item id="00100687" label="A/161i r" lcn="005417714" notes="A/161-182"/>
    <item id="00100688" label="A/161i v" lcn="" notes=""/>
    <item id="00100819" label="A/182ii v" lcn="" notes=""/>
    <item id="00100820" label="A/182iii r" lcn="" notes=""/>
    <item id="00100821" label="A/182iii v" lcn="" notes=""/>
  </lcn>
  <lcn lcn="005417715">
    <item id="00100822" label="A/183i r" lcn="005417715" notes="A/183-218"/>
    <item id="00100823" label="A/183i v" lcn="" notes=""/>
    <item id="00100975" label="A/216iii r" lcn="" notes=""/>
    <item id="00100976" label="A/216iii v" lcn="" notes=""/>
    <item id="00100977" label="A/217i r" lcn="" notes=""/>
    <item id="00100978" label="A/217i v" lcn="" notes=""/>
    <item id="00100979" label="A/217ii r" lcn="" notes=""/>
    <item id="00100980" label="A/217ii v" lcn="" notes=""/>
    <item id="00100981" label="A/218i r" lcn="" notes=""/>
    <item id="00100982" label="A/218i v" lcn="" notes=""/>
    <item id="00100983" label="A/218ii r" lcn="" notes=""/>
    <item id="00100984" label="A/218ii v" lcn="" notes=""/>
  </lcn>
  <lcn lcn="005417716">
    <item id="00100985" label="A/219i r" lcn="005417716" notes="A/219-248"/>
    <item id="00100986" label="A/219 v" lcn="" notes=""/>
    <item id="00100987" label="A/219ii r" lcn="" notes=""/>
    <item id="00101061" label="A/248 r" lcn="" notes=""/>
    <item id="00101062" label="A/248 v" lcn="" notes=""/>
  </lcn>
</items>

使用xslt-1.0,您可以尝试以下基于密钥的解决方案: (只是为了说明它是如何工作的)


将生成以下输出:

<items>
  <lcn lcn="005417713">
    <item id="00100537" label="A/137i r" lcn="005417713" notes="A/137-160"/>
    <item id="00100538" label="A/137i v" lcn="" notes=""/>
    <item id="00100539" label="A/137ii r" lcn="" notes=""/>
    <item id="00100540" label="A/137ii v" lcn="" notes=""/>
    <item id="00100678" label="A/159iii v" lcn="" notes=""/>
    <item id="00100679" label="A/159iv r" lcn="" notes=""/>
    <item id="00100680" label="A/159iv v" lcn="" notes=""/>
    <item id="00100681" label="A/160i r" lcn="" notes=""/>
    <item id="00100682" label="A/160i v" lcn="" notes=""/>
    <item id="00100683" label="A/160ii r" lcn="" notes=""/>
    <item id="00100684" label="A/160ii v" lcn="" notes=""/>
    <item id="00100685" label="A/160iii r" lcn="" notes=""/>
    <item id="00100686" label="A/160iii v" lcn="" notes=""/>
  </lcn>
  <lcn lcn="005417714">
    <item id="00100687" label="A/161i r" lcn="005417714" notes="A/161-182"/>
    <item id="00100688" label="A/161i v" lcn="" notes=""/>
    <item id="00100819" label="A/182ii v" lcn="" notes=""/>
    <item id="00100820" label="A/182iii r" lcn="" notes=""/>
    <item id="00100821" label="A/182iii v" lcn="" notes=""/>
  </lcn>
  <lcn lcn="005417715">
    <item id="00100822" label="A/183i r" lcn="005417715" notes="A/183-218"/>
    <item id="00100823" label="A/183i v" lcn="" notes=""/>
    <item id="00100975" label="A/216iii r" lcn="" notes=""/>
    <item id="00100976" label="A/216iii v" lcn="" notes=""/>
    <item id="00100977" label="A/217i r" lcn="" notes=""/>
    <item id="00100978" label="A/217i v" lcn="" notes=""/>
    <item id="00100979" label="A/217ii r" lcn="" notes=""/>
    <item id="00100980" label="A/217ii v" lcn="" notes=""/>
    <item id="00100981" label="A/218i r" lcn="" notes=""/>
    <item id="00100982" label="A/218i v" lcn="" notes=""/>
    <item id="00100983" label="A/218ii r" lcn="" notes=""/>
    <item id="00100984" label="A/218ii v" lcn="" notes=""/>
  </lcn>
  <lcn lcn="005417716">
    <item id="00100985" label="A/219i r" lcn="005417716" notes="A/219-248"/>
    <item id="00100986" label="A/219 v" lcn="" notes=""/>
    <item id="00100987" label="A/219ii r" lcn="" notes=""/>
    <item id="00101061" label="A/248 r" lcn="" notes=""/>
    <item id="00101062" label="A/248 v" lcn="" notes=""/>
  </lcn>
</items>

在XSLT 2.0中,您可以使用
,尤其是它的
组,以
属性开头,迭代以非空
lcn
开头的元素组。在XSLT1.0中有各种可能性。最简单的方法是

<xsl:for-each select="/items/item[@lcn='005417714']">
  <xsl:for-each select="following-sibling::*[
         generate-id(preceding-sibling::item[@lcn != ''][1])
       = generate-id(current())]">
  </xsl:for-each>
</xsl:for-each>

它检查目标项的以下所有同级项,并选择其最近的具有非空
lcn
属性的前一同级项为目标项的同级项


如果您想迭代所有的“部分”,而不是只针对一个特定的部分,那么基于键的分组方法将更加有效。

在XSLT2.0中,您可以使用
,尤其是从
属性开始的
组来迭代以非空
lcn
开始的元素组。在XSLT1.0中有各种可能性。最简单的方法是

<xsl:for-each select="/items/item[@lcn='005417714']">
  <xsl:for-each select="following-sibling::*[
         generate-id(preceding-sibling::item[@lcn != ''][1])
       = generate-id(current())]">
  </xsl:for-each>
</xsl:for-each>

它检查目标项的以下所有同级项,并选择其最近的具有非空
lcn
属性的前一同级项为目标项的同级项


如果您想迭代所有的“部分”,而不是只针对一个特定的部分,那么基于键的分组方法将更有效。

XSLT1.0,但我还没有尝试过2.0。我可以从2.0中给出一个解决方案,看看它是否有效。XSLT1.0,但我还没有尝试过2.0。我可以给出一个2.0版的解决方案,看看是否有效。就像这是一条路要走。您可以完全在xpath中完成,但密钥的性能要好得多。我有一个4MB(不是一个大文件)的模板匹配,使用xpath,速度很慢。我换了一把这样的钥匙,现在一眨眼就跑了。就像这是一条路要走。您可以完全在xpath中完成,但密钥的性能要好得多。我有一个4MB(不是一个大文件)的模板匹配,使用xpath,速度很慢。我换了一把这样的钥匙,现在一眨眼就跑了。