简体   繁体   English

xsl href在chrome中不起作用

[英]xsl href not working in chrome

I have used the following code in my XSL: 我在XSL中使用了以下代码:

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

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

It should navigate to chapter 2 position on click of the next chapter link. 单击下一章链接,它应该导航到第二章的位置。 Its not navigating to chapter 2 in chrome and firefox. 它没有导航到chrome和firefox中的第2章。 When I hover to the link I found that in chrome and firefox after '#' some extra characters gets added like #14678776e_chapter2. 当我将鼠标悬停在链接上时,我发现在chrome和Firefox中,“#”之后添加了一些额外的字符,例如#14678776e_chapter2。

How to fix this issue. 如何解决此问题。

$chapter2 is position() value Code: $ chapter2是position()值代码:

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

Code for xsl: 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>

There is no input xml for now. 目前没有输入xml。 The above code can be run directly 上面的代码可以直接运行

Thanks, Sam 谢谢山姆

The name "chapter2" needs to be surrounded by quotes: 名称“ chapter2”需要用引号引起来:

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

Also, make sure the template that defines chapter2 is not the same that defines chapter1, or else the variable binding of chapter1 will shadow the variable binding of chapter2, since both will equal the result of the position function. 另外,请确保定义第2章的模板与定义第1章的模板不同,否则第1章的变量绑定将遮盖第2章的变量绑定,因为这两者将等于位置函数的结果。 This code works fine: 这段代码可以正常工作:

<?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