Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an XML file(below is a part of it) with more than 1000 lines of code like below

<?xml version="1.0" encoding="UTF-8" ?>

<exchange xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<viewpoints>    
    <view name="002. PG vs MD - Overview">
            <viewpoint tool="none" render="shaded" lighting="headlight" focal="30.3740807783">
                <camera projection="persp" near="1.0000000000" far="10.0000000000" aspect="1.4551804424" height="0.7853981634">
                    <position>
                        <pos3f x="14.2834498406" y="-183.6741132934" z="35.6151508952"/>
                    </position>
                    <rotation>
                        <quaternion a="0.3979643079" b="0.0563656552" c="0.1284089725" d="0.9066192466"/>
                    </rotation>
                </camera>
            </viewpoint>
        </view>

        <view name="004. EL vs MD - Overview">
            <viewpoint tool="none" render="shaded" lighting="headlight" focal="30.3740807783">
                <camera projection="persp" near="1.0000000000" far="10.0000000000" aspect="1.4551804424" height="0.7853981634">
                    <position>
                        <pos3f x="14.2834498406" y="-183.6741132934" z="35.6151508952"/>
                    </position>
                    <rotation>
                        <quaternion a="0.3979643079" b="0.0563656552" c="0.1284089725" d="0.9066192466"/>
                    </rotation>
                </camera>
            </viewpoint>
        </view>
    </viewpoints>
</exchange>

I would like to sort the code above using the attribute "name" but I would like it to sort using the first word in the attribute value. In the above example, I would like it sore using PG/EL.

P.S: Please note that I'm not very familiar with XSLT or any other tools, but I can probably understand it with little explanation.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
222 views
Welcome To Ask or Share your Answers For Others

1 Answer

You've given an example with two elements to be sorted, and for both elements, the "first word" can be obtained as substring(@name, 6, 2) or as substring-after(substring-before(@name, ' '), ' '). If either of these expressions work for all your data, then use them as the sort key in xsl:sort. Otherwise, you need to tell us

(a) what exactly you mean by a "word"

(b) what version of XSLT you are using (any more complex string manipulation is going to be an awful lot easier if you can use XSLT 2.0)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...