开发者

xslt - Need the largest value in an element set, not including default (99999999)

开发者 https://www.devze.com 2023-01-17 12:41 出处:网络
given the simple xml snipet... <workers> <worker> <name>Fred</name> <dob>19410501</dob>

given the simple xml snipet...

<workers>
  <worker>
    <name>Fred</name>
    <dob>19410501</dob>
  </worker>
  <worker>
    <name>Fred</name>
    <dob>19410501</dob>
  </worker>
  <worker>
    <name>Mary</name>
    <dob>99999999</dob>
  </worker>
  <worker&g开发者_运维技巧t;
    <name>Sam</name>
    <dob>19361202</dob>
  </worker>
</workers>

I need to write some xslt that will produce just the oldest persons name NOT including the default entry of '99999999'. So, Mary refuses to give her DOB.... so my report needs to look at the other workers and provide the oldest persons name. Result should look like this:

<html>
  <body>
    Sam
  </body>
</html>

I can do this if I don't have any default DOB of 99999999. Like this...

<xsl:for-each select="workers/worker">
  <xsl:sort select="dob" data-type="number" order="descending" />
  <xsl:if test="position() = 1">
<html>
  <body>
    <xsl:value-of select="name" />
  </body>
</html>
  </xsl:if>
</xsl:for-each>

That default DOB, however, is just causing me fits.

Any ideas?


My XSLT is a little rusty but try somethign like this. Important part is selecting all workers that DO NOT have a birthday of 99999999 in your for-each select.

<xsl:for-each select="workers/worker[dob!='99999999']">
  <xsl:sort select="dob" data-type="number" order="descending" />
  <xsl:if test="position() = 1">
<html>
  <body>
    <xsl:value-of select="name" />
  </body>
</html>
  </xsl:if>
</xsl:for-each>
0

精彩评论

暂无评论...
验证码 换一张
取 消