Xml 如何在xsl模板中直接包含子元素

Xml 如何在xsl模板中直接包含子元素,xml,internet-explorer,xslt,Xml,Internet Explorer,Xslt,我有一个显示gpx文件中航路点的模板。目前,我可以向项目添加子元素的唯一方法是使用模板。有没有一种方法可以在不使用单独模板的情况下获取子元素的值?因此,与其这样做,不如: <xsl:attribute name="href"> <xsl:apply-templates select="gpx:link" /> </xsl:attribute> 我可以这样做: <xsl:attribute name="href"> <xsl:valu

我有一个显示gpx文件中航路点的模板。目前,我可以向项目添加子元素的唯一方法是使用模板。有没有一种方法可以在不使用单独模板的情况下获取子元素的值?因此,与其这样做,不如:

<xsl:attribute name="href">
  <xsl:apply-templates select="gpx:link" />
</xsl:attribute>
我可以这样做:

<xsl:attribute name="href">
  <xsl:value-of select="child@href" />
</xsl:attribute>
这里是我用于它的xml和xsl

<wpt lat="00.00000000" lon="00.00000000">
    <ele>600</ele>
    <time>2015-02-16T06:12:27Z</time>
    <name><![CDATA[Photo]]></name>
    <link href="2015-02-16_01-12-27.jpg">
        <text>2015-02-16_01-12-27.jpg</text>
    </link>
    <sat>0</sat>
</wpt>

<xsl:template name="wpt-circle">
  <xsl:for-each select="gpx:wpt">
    <circle stroke="black" stroke-width="3" fill="red" r="6">
      <xsl:call-template name="latlonc">
        <xsl:with-param name="lon" select="@lon"/>
        <xsl:with-param name="lat" select="@lat"/>
      </xsl:call-template>
      <xsl:attribute name="text">
        <xsl:apply-templates select="gpx:name" />
      </xsl:attribute>
      <xsl:attribute name="href">
        <xsl:apply-templates select="gpx:link" />
      </xsl:attribute>
    </circle>
  </xsl:for-each>
</xsl:template>

<xsl:template match="gpx:name">
  <xsl:value-of select="." />
</xsl:template>

<xsl:template match="gpx:link">
  <xsl:value-of select="@href" />
</xsl:template>

你要找的是这个吗

<xsl:attribute name="href">
   <xsl:value-of select="gpx:link/@href" />
</xsl:attribute> 
您可以在这里的select参数中使用任何XPath表达式,而不仅仅是单个子节点

事实上,你也可以这样做

<circle stroke="black" stroke-width="3" fill="red" r="6" href="{gpx:link/@href}">
这被称为,用大括号{}表示要计算的表达式,而不是字面上的输出