0

我在下面提到了我的示例 xml 文件。我想以value我自己的订单格式显示标签文本。EX:首先我想显示 Value AttributeID="13222"然后 Value AttributeID="113458"这样,我需要根据AttributeId排列位置。

示例.xml

<?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl"?>
    <Values>     
      <Value AttributeID="113458" AttributeName="0180 - Text - remainder">
        <Text>
          <style name="TextHead1">The current enterprise application landscape</style>
          <style name="TextStyle1">
            <character name="linebreak" />Introduction of the Title
            <style name="bold">
              The smallest font size
              <character name="linebreak" />
              for which kerning should be automatically adjusted.
              <character name="linebreak" />
              and some manual work done.
            </style>
            <style name="bold">
              Reference for this book<style name="superscript">1</style>
            </style>     
        </Text>
      </Value>
      <Value AttributeID="13335" AttributeName="0190 - Text - remainder">
        <Text>
          <style name="TextHead1">The Bussiness application landscape</style>
          <style name="TextStyle1">
            Introduction of the Title
            <style name="bold">
              The smallest font size for which kerning should be automatically adjusted and some manual work done.
            </style>
             <style name="SimpleTag target=&quot;http://www.example.com/financing /uk&quot;"><style name="URL_bold">ibm.com</style></style>
            <style name="italic">
              Reference for this book<style name="superscript">1</style>
            </style>
            <style name="bulletStyle1">none: No leader line</style>
            <style name="bulletStyle1">dot: Dotted leader line</style>
          </Text>
      </Value>   
    <Value AttributeID="13222" AttributeName="0200 - Text - remainder">
        <Text>
          <style name="TextHead1">the world’s largest florist and gift shop</style>
          <style name="TextStyle1">
            Introduction of the Title, It is also introducing environmental responsibility as a theme across all of its businesses,        
              The smallest font size for some manual work done.       
             <style name="SimpleTag target=&quot;http://www.example.com/financing /uk&quot;"><style name="URL_bold">ibm.com</style></style>
            <style name="italic">
              Reference for this book<style name="superscript">1</style>
            </style>
            <style name="bulletStyle1">environmental responsibility</style>
            <style name="bulletStyle1">world’s largest florist</style>
          </Text>
      </Value>     
    </Values>
4

1 回答 1

0

这是您如何在 XSLT 中设置自定义排序的示例:

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="Values">
        <values>
          <xsl:for-each select="Value">
            <xsl:sort data-type="number" order="ascending"
              select="(number(@AttributeID='13222') * 1)
          + (number(@AttributeID='113458') * 2)
          + (number(@AttributeID='13335') * 3) "/>
            <xsl:copy-of select="."/>
          </xsl:for-each>
        </values>
      </xsl:template>
    </xsl:stylesheet>

INPUT XML因为您的 XML 格式不正确:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl"?>
<Values>     
  <Value AttributeID="113458" AttributeName="0180 - Text - remainder">
    <Text>
      <style name="TextHead1">The current enterprise application landscape</style>
      <style name="TextStyle1">
            <character name="linebreak" />Introduction of the Title
            <style name="bold">
              The smallest font size
              <character name="linebreak" />
              for which kerning should be automatically adjusted.
              <character name="linebreak" />
              and some manual work done.
            </style>
            <style name="bold">
              Reference for this book<style name="superscript">1</style>
            </style>
        </style>
        </Text>
  </Value>
  <Value AttributeID="13335" AttributeName="0190 - Text - remainder">
    <Text>
      <style name="TextHead1">The Bussiness application landscape</style>
      <style name="TextStyle1">
            Introduction of the Title
            <style name="bold">
              The smallest font size for which kerning should be automatically adjusted and some manual work done.
            </style>
             <style name="SimpleTag target=&quot;http://www.example.com/financing /uk&quot;"><style name="URL_bold">ibm.com</style></style>
            <style name="italic">
              Reference for this book<style name="superscript">1</style>
            </style>
            <style name="bulletStyle1">none: No leader line</style>
            <style name="bulletStyle1">dot: Dotted leader line</style>
        </style>
          </Text>
  </Value>   
  <Value AttributeID="13222" AttributeName="0200 - Text - remainder">
    <Text>
      <style name="TextHead1">the world’s largest florist and gift shop</style>
      <style name="TextStyle1">
            Introduction of the Title, It is also introducing environmental responsibility as a theme across all of its businesses,        
              The smallest font size for some manual work done.       
             <style name="SimpleTag target=&quot;http://www.example.com/financing /uk&quot;"><style name="URL_bold">ibm.com</style></style>
            <style name="italic">
              Reference for this book<style name="superscript">1</style>
            </style>
            <style name="bulletStyle1">environmental responsibility</style>
            <style name="bulletStyle1">world’s largest florist</style>
        </style>
          </Text>
  </Value>     
</Values>

生成的输出:

<?xml version="1.0" encoding="utf-8"?><values><Value AttributeID="13222" AttributeName="0200 - Text - remainder">
    <Text>
      <style name="TextHead1">the world’s largest florist and gift shop</style>
      <style name="TextStyle1">
            Introduction of the Title, It is also introducing environmental responsibility as a theme across all of its businesses,        
              The smallest font size for some manual work done.       
             <style name="SimpleTag target=&#34;http://www.example.com/financing /uk&#34;"><style name="URL_bold">ibm.com</style></style>
            <style name="italic">
              Reference for this book<style name="superscript">1</style>
            </style>
            <style name="bulletStyle1">environmental responsibility</style>
            <style name="bulletStyle1">world’s largest florist</style>
        </style>
          </Text>
  </Value><Value AttributeID="113458" AttributeName="0180 - Text - remainder">
    <Text>
      <style name="TextHead1">The current enterprise application landscape</style>
      <style name="TextStyle1">
            <character name="linebreak"/>Introduction of the Title
            <style name="bold">
              The smallest font size
              <character name="linebreak"/>
              for which kerning should be automatically adjusted.
              <character name="linebreak"/>
              and some manual work done.
            </style>
            <style name="bold">
              Reference for this book<style name="superscript">1</style>
            </style>
        </style>
        </Text>
  </Value><Value AttributeID="13335" AttributeName="0190 - Text - remainder">
    <Text>
      <style name="TextHead1">The Bussiness application landscape</style>
      <style name="TextStyle1">
            Introduction of the Title
            <style name="bold">
              The smallest font size for which kerning should be automatically adjusted and some manual work done.
            </style>
             <style name="SimpleTag target=&#34;http://www.example.com/financing /uk&#34;"><style name="URL_bold">ibm.com</style></style>
            <style name="italic">
              Reference for this book<style name="superscript">1</style>
            </style>
            <style name="bulletStyle1">none: No leader line</style>
            <style name="bulletStyle1">dot: Dotted leader line</style>
        </style>
          </Text>
  </Value></values>
于 2013-05-17T09:02:23.420 回答