Html 如何将xsl值转换为字符串?

Html 如何将xsl值转换为字符串?,html,xml,xslt,Html,Xml,Xslt,我想将网页重定向到xyz属性中保留的值 <meta http-equiv="refresh" content="0; url=<xsl:value-of select="xyz"/>"></meta> 上述方法不起作用。我尝试了一些其他的排列,但它们也不起作用 我应该在这里找什么?使用一些转换运算符将值转换为字符串,以便重定向到它?我认为最好的方法是使用xsl:attribute。 那你应该有这样的东西 XML <root> <re

我想将网页重定向到xyz属性中保留的值

<meta http-equiv="refresh" content="0; url=<xsl:value-of select="xyz"/>"></meta>

上述方法不起作用。我尝试了一些其他的排列,但它们也不起作用


我应该在这里找什么?使用一些转换运算符将值转换为字符串,以便重定向到它?

我认为最好的方法是使用
xsl:attribute
。 那你应该有这样的东西

XML

<root>
  <redirects>
    <xyz url="http://www.example.com" />
  </redirects>
</root>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="root/redirects/">
    <html>
      <body>
        <meta>
          <xsl:attribute name="http-equiv">refresh</xsl:attribute>
          <xsl:attribute name="content">0</xsl:attribute>
          <xsl:attribute name="url"><xsl:value-of select="xyz"/></xsl:attribute>
        </meta>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

HTML

<root>
  <redirects>
    <xyz url="http://www.example.com" />
  </redirects>
</root>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="root/redirects/">
    <html>
      <body>
        <meta>
          <xsl:attribute name="http-equiv">refresh</xsl:attribute>
          <xsl:attribute name="content">0</xsl:attribute>
          <xsl:attribute name="url"><xsl:value-of select="xyz"/></xsl:attribute>
        </meta>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

刷新
0

我认为最好的方法是使用
xsl:attribute
。 那你应该有这样的东西

XML

<root>
  <redirects>
    <xyz url="http://www.example.com" />
  </redirects>
</root>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="root/redirects/">
    <html>
      <body>
        <meta>
          <xsl:attribute name="http-equiv">refresh</xsl:attribute>
          <xsl:attribute name="content">0</xsl:attribute>
          <xsl:attribute name="url"><xsl:value-of select="xyz"/></xsl:attribute>
        </meta>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

HTML

<root>
  <redirects>
    <xyz url="http://www.example.com" />
  </redirects>
</root>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="root/redirects/">
    <html>
      <body>
        <meta>
          <xsl:attribute name="http-equiv">refresh</xsl:attribute>
          <xsl:attribute name="content">0</xsl:attribute>
          <xsl:attribute name="url"><xsl:value-of select="xyz"/></xsl:attribute>
        </meta>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>

刷新
0

在文本结果元素中,属性值由属性值模板指定。在属性值模板中,大括号中包含的部分值将作为XPath表达式计算。因此,可以通过以下方式实现您想要的效果:

<meta http-equiv="refresh" 
      content="0; url={$xyz}" ></meta>


正如S.Visser所建议的那样,使用显式属性构造函数也是解决问题的一个非常好的方法。

在文本结果元素中,属性值是通过属性值模板指定的。在属性值模板中,大括号中包含的部分值将作为XPath表达式计算。因此,可以通过以下方式实现您想要的效果:

<meta http-equiv="refresh" 
      content="0; url={$xyz}" ></meta>


正如S.Visser所建议的那样,使用显式属性构造函数也是解决问题的一个非常好的方法。

您的xml看起来怎么样?您的xml看起来怎么样?我收到一个错误,它是
javax.xml.transform.TransformerConfiguration异常:“root/redirects/”中的语法错误。
。是否需要模板匹配?如果您离开它,您应该使用
。我收到一个错误,它是
javax.xml.transform.transformerConfiguration异常:“root/redirects/”中的语法错误。
。是否需要模板匹配?如果保留模板,则应使用