首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >基于XML节点的XML文件排序&使用XSLT的XML注释标记

基于XML节点的XML文件排序&使用XSLT的XML注释标记
EN

Stack Overflow用户
提问于 2010-11-08 14:04:15
回答 1查看 241关注 0票数 0

可能重复:

Sorting XML file based on XML nodes & XML comments using XSLT

大家好,

在基于XML节点对xml文件进行排序时,我需要帮助,还有一件事是,我必须将它们的注释标记与该节点相对应。

例如:输入XML文件是

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="UTF-8"?>
<!-- catalog main -->
<catalog>
 <!-- first book id -->
 <book id="bk101">
  <!-- author name 1 -->
  <author>Gambardella, Matthew</author>
  <!-- title name 1 -->
  <title>XML Developer's Guide</title>
  <genre>Computer</genre>
  <!-- price 1 -->
  <price>44.95</price>
  <publish_date>2000-10-01</publish_date>
  <description>An in-depth look at creating applications 
      with XML.</description>
 </book>
 <Book id="bk102">
  <author>Ralls, Kim</author>
  <title>Midnight Rain</title>
  <genre>Fantasy</genre>
  <price>5.95</price>
  <publish_date>2000-12-16</publish_date>
  <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
 </Book>


 <!-- languages -->
 <Languages>
  <!-- java comment -->
  <java>Galos, Mike</java>
  <c>Visual Studio 7: A Comprehensive Guide</c>
  <!-- dotnet comment -->
  <dotnet>Computer</dotnet>
  <!-- description -->
  <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.</description>
 </Languages>

 <!-- ABC book -->
 <ABC>
  <!-- ABC author -->
  <author1>Galos, Mike</author1>
  <title1>Visual Studio 7: A Comprehensive Guide</title1>
  <!-- ABC genre -->
  <genre1>Computer</genre1>
  <price1>49.95</price1>
  <publish_date>2001-04-16</publish_date>
  <!-- ABC description -->
  <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.</description>
 </ABC>
 <!-- ABC1 book -->
 <abc1>
  <!-- ABC1 author -->
  <author1>Galos, Mike</author1>
  <title1>Visual Studio 7: A Comprehensive Guide</title1>
  <!-- ABC1 genre -->
  <genre1>Computer</genre1>
  <price1>49.95</price1>
  <publish_date>2001-04-16</publish_date>
  <!-- ABC1 description -->
  <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.</description>
 </abc1>
</catalog>

预期的输出XML文件应该是:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="UTF-8"?>
<!-- catalog main -->
<catalog>
 <!-- ABC book -->
 <ABC>
  <!-- ABC author -->
  <author1>Galos, Mike</author1>
  <!-- ABC description -->
  <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.</description>
  <!-- ABC genre -->
  <genre1>Computer</genre1>
  <price1>49.95</price1>
  <publish_date>2001-04-16</publish_date>
  <title1>Visual Studio 7: A Comprehensive Guide</title1>
 </ABC>
 <!-- ABC1 book -->
 <abc1>
  <!-- ABC1 author -->
  <author1>Galos, Mike</author1>
  <!-- ABC1 description -->
  <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.</description>
  <!-- ABC1 genre -->
  <genre1>Computer</genre1>
  <price1>49.95</price1>
  <publish_date>2001-04-16</publish_date>
  <title1>Visual Studio 7: A Comprehensive Guide</title1>
 </abc1>
 <!-- first book id -->
 <book id="bk101">
  <!-- author name 1 -->
  <author>Gambardella, Matthew</author>
  <description>An in-depth look at creating applications 
      with XML.</description>
  <genre>Computer</genre>
  <!-- price 1 -->
  <price>44.95</price>
  <publish_date>2000-10-01</publish_date>
  <!-- title name 1 -->
  <title>XML Developer's Guide</title>
 </book>
 <Book id="bk102">
  <author>Ralls, Kim</author>
  <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
  <genre>Fantasy</genre>
  <price>5.95</price>
  <publish_date>2000-12-16</publish_date>
  <title>Midnight Rain</title>
 </Book>
 <!-- languages -->
 <Languages>
  <c>Visual Studio 7: A Comprehensive Guide</c>
  <!-- description -->
  <description>Microsoft Visual Studio 7 is explored in depth,
      looking at how Visual Basic, Visual C++, C#, and ASP+ are 
      integrated into a comprehensive development 
      environment.</description>
  <!-- dotnet comment -->
  <dotnet>Computer</dotnet>
  <!-- java comment -->
  <java>Galos, Mike</java>
 </Languages>
</catalog>
EN

回答 1

Stack Overflow用户

发布于 2010-11-08 14:21:12

这个问题与我在另一个问题中所提的类似。

以下是网址:

Sorting XML file based on XML nodes & XML comments using XSLT

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4124560

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档