How to reorder node elements such that they match an xsd:sequence order?

后端 未结 3 622
青春惊慌失措
青春惊慌失措 2021-01-25 13:16

Is there any way to reorder elements in a Node objects such that they match an xsd:sequence order? I\'ve read through the docs for Node.normalize, but

3条回答
  •  佛祖请我去吃肉
    2021-01-25 13:58

    If you only have xs:sequence to worry about, and not choice/repetition, and so long as the schema isn't written to use lots of complex features like named model groups and substitution groups and wildcards, then it shouldn't be too difficult, at any rate if you use XSLT 2.0 or XQuery and forget about trying to code it in Java. If the variable $seq is an xs:sequence element, then the sort key for an element named $E is "count($x/xs:element[(@name|@ref)=$E]/preceding-sibling::*", so you can just plug this expression into an xsl:sort as

    
      
      ...
    
    

    Probably needs a bit of finessing for namespaces or other things you might encounter, but you get the idea.

提交回复
热议问题