【问题标题】:Get Max value from two different nodes XSLT从两个不同的节点 XSLT 获取最大值
【发布时间】:2018-04-25 07:24:50
【问题描述】:

我无法从 NrOfConvoysannotationText 节点中找到最大值,下面是我的 XML 文件。

<InstructionListPosition>
  <Instruction>
    <Navigation>
      <NrOfConvoys>2</NrOfConvoys>
      <annotationText>5</annotationText>
    </Navigation>
  </Instruction>
</InstructionListPosition>
<InstructionListPosition>
  <Instruction>
    <Navigation>
      <NrOfConvoys>20</NrOfConvoys>
      <annotationText>10</annotationText>
    </Navigation>
  </Instruction>
</InstructionListPosition>

我想要输出如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--Disable Cache-->
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="pragma" content="no-cache" />
<!--End-->
</head>

<body>
<div id="wrapper_all">
	<table style="width:100%">
  <tr>
    <th>Sr. Num</th>
    <th>Maximum value</th> 
  </tr>
  <tr>
    <td>1</td>
    <td>5</td>     
  </tr>
    <tr>
    <td>2</td>
    <td>20</td>     
  </tr>
</table>
</div>
</body>
</html>

我想要如上所示的输出,请您提供最佳解决方案。我正在使用 XSLT1.0。

请帮帮我,谢谢。

【问题讨论】:

  • 您使用的 XSLT 是什么,它有什么问题?

标签: c# xml xslt-1.0


【解决方案1】:

使用这个:

<xsl:for-each select="InstructionListPosition">
                <tr>
                    <td>
                        <xsl:value-of select="position()"/>
                    </td>
                    <td>
                        <xsl:for-each
                            select=".//Navigation/*[self::NrOfConvoys or self::annotationText]">
                            <xsl:sort select="." order="descending"/>
                            <xsl:if test="position()=1">
                                <xsl:value-of select="."/>
                            </xsl:if>
                        </xsl:for-each>
                    </td>
                </tr>
            </xsl:for-each>

https://xsltfiddle.liberty-development.net/gWmuiJ1/1查看转换

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-10
    • 2016-04-30
    • 1970-01-01
    • 2012-08-22
    • 1970-01-01
    相关资源
    最近更新 更多