簡體   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