繁体   English   中英

xsl href在chrome中不起作用

[英]xsl href not working in chrome

我在XSL中使用了以下代码:

<xsl:variable name="link" select="normalize-space(concat('#',$chapter2))/>

<a href="{$link}">Next chapter</a>

单击下一章链接,它应该导航到第二章的位置。 它没有导航到chrome和firefox中的第2章。 当我将鼠标悬停在链接上时,我发现在chrome和Firefox中,“#”之后添加了一些额外的字符,例如#14678776e_chapter2。

如何解决此问题。

$ chapter2是position()值代码:

<xsl:variable name=chapter2 select="position()"/>

xsl的代码:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
        xmlns:xsl="w3.org/1999/XSL/Transform";
        xmlns:msxsl="urn:schemas-microsoft-com:xslt"
        exclude-result-prefixes="msxsl"> 

    <xsl:output method="html" indent="yes"/> 

    <xsl:template match="/">
        <xsl:variable name="chapter" select="position()"/>
        <xsl:variable name="link" select="concat('#',$chapter)"/>
        <a href="{$link}" title="{$link}">
            <xsl:value-of select="$link"/>
        </a>
    </xsl:template>

</xsl:stylesheet>

目前没有输入xml。 上面的代码可以直接运行

谢谢山姆

名称“ chapter2”需要用引号引起来:

<xsl:variable name=chapter2 select="position()"/>

另外,请确保定义第2章的模板与定义第1章的模板不同,否则第1章的变量绑定将遮盖第2章的变量绑定,因为这两者将等于位置函数的结果。 这段代码可以正常工作:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="pitarget.xml"?>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"
                >
<xsl:variable name="gal" select="'howdy'"/>
<?var gal?><!--howdy-->
<?echo gal?>
<?html5 ?>

<xsl:output method="html" encoding="utf-8" version="" indent="yes" standalone="no" media-type="text/html" omit-xml-declaration="no" doctype-system="about:legacy-compat" />

<xsl:template match="xsl:stylesheet">
  <xsl:apply-templates select="processing-instruction()"/>
</xsl:template>

<xsl:template match="/">
  <xsl:variable name="chapter" select="position()"/>
  <xsl:variable name="link" select="concat('#',$chapter)"/>
  <xsl:value-of select="processing-instruction('html5')"/>
  <a href="{$link}" title="{$link}"><xsl:value-of select="$link"/></a>
  <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    </head>
    <body>
      <xsl:apply-templates/>
    </body>
  </html>
</xsl:template>


<xsl:template match="processing-instruction('echo')">
  <xsl:variable name="chapter2" select="position()"/>
  <xsl:variable name="link" select="normalize-space(concat('#',$chapter2))"/>
  <a href="{$link}">Next chapter</a>
  <xsl:value-of select="//xsl:variable/@select[../@name=current()]"/>
  <xsl:value-of select="count(document('pitarget.xml')//*) - 1"/>
</xsl:template>

<xsl:template match="processing-instruction('var')">
  <xsl:processing-instruction name="{.}">
    <xsl:value-of select="."/>
    <xsl:value-of select="./following-sibling::node()"/>
  </xsl:processing-instruction>
</xsl:template>

</xsl:stylesheet>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM