简体   繁体   中英

XSLT get child nodes

how can I get the child nodes from an xslt? This is how my structure looks like: ``

<?xml version="1.0" encoding="UTF-8"?>
<objects>
    <object>
        <cats>
            <cat>
                <entity_id>1</entity_id>
            </cat>
            <cat>
                <entity_id>2</entity_id>
            </cat>
            <cat>
                <entity_id>10</entity_id>
            </cat>
    </object>
</objects>

I've tried cats/cat/entity_id but then I only get the first entity_id how can I get the second or third? Thanks

找到了cats/cat[2]/entity_id的答案,我可以得到第二个

The idea to make "enumerative" references to particular instances is not a good solution.

In XSLT 1.0, if you use eg xsl:value-of with select returning mutliple nodes, then xsl:value-of takes only the first returned item and the rest apparently "vanishes".

In order to process the full returned sequence you have to:

  • store it in a variable,
  • process it in a loop ( for-each ).

This feature has been changed in XSLT 2.0, where:

  • all returned items are output,
  • there is separator attribute, stating what to insert between consecutive items.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM