我正在嘗試使用XSL對XML文件進行排序。我對XSL相當陌生,並且編寫了一個.Net應用程序將XSL應用於XML並將其保存到新文件。這工作正常。該XML的一個簡化版本是這樣的(細心的讀者會注意到,這是一個管理Studio項目文件):如何使用XSL對XML文件的一部分進行排序
<?xml version="1.0"?>
<SqlWorkbenchSqlProject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Name="PMISQL">
<Items>
<LogicalFolder Name="Connections" Type="2" Sorted="true">
<Items>
<ConnectionNode Name="cerberus:XPOOLE\barney.russ">
<Created>2013-06-28T15:50:27.919788+01:00</Created>
<Type>SQL</Type>
<Server>cerberus</Server>
<UserName />
<Authentication>Windows Authentication</Authentication>
<InitialDB>master</InitialDB>
<LoginTimeout>15</LoginTimeout>
<ExecutionTimeout>0</ExecutionTimeout>
<ConnectionProtocol>NotSpecified</ConnectionProtocol>
<ApplicationName>Microsoft SQL Server Management Studio - Query</ApplicationName>
</ConnectionNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Queries" Type="0" Sorted="true">
<Items>
<FileNode Name="PMI193_Documents.sql">
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:tyro:True</AssociatedConnectionMoniker>
<AssociatedConnSrvName>tyro</AssociatedConnSrvName>
<AssociatedConnUserName />
<FullPath>PMI193_Documents.sql</FullPath>
</FileNode>
<FileNode Name="PMI002_EventTypes.sql">
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:cerberus:True</AssociatedConnectionMoniker>
<AssociatedConnSrvName>cerberus</AssociatedConnSrvName>
<AssociatedConnUserName />
<FullPath>PMI002_EventTypes.sql</FullPath>
</FileNode>
<FileNode Name="PMI079a_DementiaScreeningDetail.sql">
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:tyro:True</AssociatedConnectionMoniker>
<AssociatedConnSrvName>tyro</AssociatedConnSrvName>
<AssociatedConnUserName />
<FullPath>PMI079a_DementiaScreeningDetail.sql</FullPath>
</FileNode>
</Items>
</LogicalFolder>
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
<Items />
</LogicalFolder>
</Items>
<SccProjectName>$/DataWarehouse/Dev/Reports</SccProjectName>
<SccAuxPath />
<SccLocalPath>..</SccLocalPath>
<SccProvider>MSSCCI:Team Foundation Server MSSCCI Provider</SccProvider>
</SqlWorkbenchSqlProject>
你會注意到,有幾個LogicalFolder部分。我只是感興趣的排序屬性名稱=「查詢」,我希望它由子元素Items/FileNode/FullPath排序。
我已經採取了一些XSL這是身份XSL並擴展它。它會複製原始文件,但不會對我想要的部分進行排序(事實上,它似乎沒有排序)。該XSL我創建看起來像這樣:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="/SqlWorkbenchSqlPro/Items/LogicalFolder/Items">
<xsl:apply-templates select=".">
<xsl:sort select="FullPath"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
我不知道如何指定我只選段/ SqlWorkbenchSqlPro /項目/ LogicalFolder /項目其中Name =「查詢」感興趣,如何指定要排序的元素級別以及如何指定使用哪個元素對項目排序。真的,我不是很擅長XSL,因爲我幾小時前纔開始看這個。
任何幫助非常感謝。我很頭疼。