我正在尝试使用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,因为我几小时前才开始看这个。
任何帮助非常感谢。我很头疼。