我有一个简单的xml文件,如下;
'<Clubs>
<Club>Long Sutton Golf Club</Club>
<Club>Enmore Park</Club>
<Club>Wheathill</Club>
<Club>Axe Cliff</Club>
<Club>Taunton & Pickeridge</Club>
<Club>Oake Manor GC</Club>
<Club>Westbury GC</Club>
<Club>Cumberwell Park</Club>
<Club>Minehead & W Somerset GC</Club>
<Club>Burnham & Berrow GC</Club>
<Club>Bath GC</Club>
<Club>Wells GC</Club>
<Club>Mendip GC</Club>
<Club>Mendip Spring GC</Club>
</Clubs>'
我想按字母顺序对球杆进行排序,所以我使用了xslt文件
这是xsl代码
'<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:strip-space elements="*"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="Clubs">
<xsl:copy>
<xsl:apply-templates select="Club">
<xsl:sort select="Club" data-type="text"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>'
这是我的XB文件的VB.net代码
'Dim xslt As New XslCompiledTransform()
xslt.Load(Path & "\Clubs.xsl")
' Execute the transform and output the results to a file.
xslt.Transform(Path & "\Clubs.xml", Path & "\sortedClubs.xml")'
我希望sortClubs.xml可以对俱乐部进行排序,但是它只是复制Clubs.xml而不进行排序。
在您的应用模板中,选择Club
。在您的排序中,还选择Club
,该排序将基于子级Club
(不存在)进行排序。
请注意,在XSLT 3.0中,整个样式表均缩小为: