Xslt returns a selection of the following siblings

I have an XML selection (edited)

<items>                 
    <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=""/>
    <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=""/>
    <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=""/>
    <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=""/>
</items>

I want to be able to get all the following nodes from a given lcn to the next lcn.

If I start with lcn = '005417714', I know that there are 4 following nodes.

But when I try to do something like this

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

I get all the following brothers and sisters. How can I get all the following siblings before the next nonempty lcn attribute? So get only 4 of the following siblings? thanks

+1
source share
2 answers

XSLT 2.0 <xsl:for-each-group> , , group-starting-with , lcn. XSLT 1.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 .

"", , hr_117.

+2

xslt-1.0 - : ( , )

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:key name="kfItem" match="item[@lcn = '']"
         use="generate-id(preceding-sibling::item[@lcn != ''][1])"/>

    <xsl:template match="/*">
        <items>
            <xsl:apply-templates select="item[@lcn != '']"/>
        </items>
    </xsl:template>

    <xsl:template match="item">
        <lcn lcn="{@lcn}">
            <xsl:copy-of select="."/>
            <xsl:copy-of select="key('kfItem', generate-id())"/>
        </lcn>
    </xsl:template>
</xsl:stylesheet>

:

<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>
+4

All Articles