如何在xslt中获取属性值?

时间:2017-04-06 10:02:55

标签: xml xslt xslt-1.0

culd yu请告诉我如何在xslt中获取属性值?我创建变量,其中full name(f)和short name(s)。 使用全名我想得到短名称

这是我的代码 http://xsltransform.net/ehVYZMp/1

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:exsl="http://exslt.org/common"
 extension-element-prefixes="exsl">
    <xsl:output method="html" doctype-public="XSLT-compat" omit-xml-declaration="yes" encoding="UTF-8" indent="yes" />
      <xsl:variable name="teams">
            <team f="Sunrisers Hyderabad" s="SRH"></team>
            <team f="Delhi Daredevils" s="DD"></team>
            <team f="Gujarat Lions" s="GL"></team>
            <team f="Kings XI Punjab" s="KXIP"></team>
            <team f="Kolkata Knight Riders" s="KKR"></team>
            <team f="Mumbai Indians" s="MI"></team>
            <team f="Rising Pune Supergiant" s="RPS"></team>
            <team f="Royal Challengers Bangalore" s="RCB"></team>
 </xsl:variable>
  <xsl:variable name="up" select="'Kings XI Punjab'"/>
    <xsl:template match="/">

      <hmtl>
        <head>
          <title>New Version!</title>
        </head>
        <xsl:value-of select="exsl:node-set($teams)/team[@f = $up]/@s"/>
      </hmtl>
    </xsl:template>


</xsl:transform>

预期输出: KXIP

1 个答案:

答案 0 :(得分:-1)

请参阅http://xsltransform.net/ehVYZMp/8处的已修改代码以获取答案。