Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
html页面上的XSL超链接_Html_Xml_Xslt_Hyperlink - Fatal编程技术网

html页面上的XSL超链接

html页面上的XSL超链接,html,xml,xslt,hyperlink,Html,Xml,Xslt,Hyperlink,我正在学习XSL,我对在一个HTML文件中生成双向超链接有疑问 例如,我们有 <person id="first"> -<name>Bob</name> -<age>19<age> <person id="second"> -<name>smith</name> -<age>12<age> <person id="third"> -<name>Lisa&

我正在学习XSL,我对在一个HTML文件中生成双向超链接有疑问

例如,我们有

<person id="first">
-<name>Bob</name>
-<age>19<age>
<person id="second">
-<name>smith</name>
-<age>12<age>
<person id="third">
-<name>Lisa</name>
-<age>30<age>

-鲍勃
-19
-史密斯
-12
-丽莎
-30
在XML文件中,我想用XSLT在一个HTML页面上创建3个超链接

例如,在HTML页面的顶部,我们有三个链接:

  • 鲍勃
  • 史密斯
  • 丽莎
  • 在同一HTML页面的底部,我们有三个链接:

  • 鲍勃
  • 史密斯
  • 丽莎
  • 如果用户单击1。鲍勃,我们去4号。页面底部的Bob(1.Bob 4.Bob)

    如果用户单击4。鲍勃,我们去1号。鲍勃在这一页的底部

    如果用户单击2。史密斯,我们去5号。史密斯在这一页的底部(5.Smith 5.Smith)

    如果用户单击5。史密斯,我们去2号。史密斯在这一页的底部

    我尝试使用

    然而,它并没有真正起作用

    有人能举个例子吗


    谢谢。

    如果您想导航到页面中的锚定标记,您需要另一个链接,该链接的href属性设置为适当的值。例如,如果锚定标记为:

    <a id="first">Bob</a>
    
    
    
    在您的情况下,您希望锚定彼此链接,因此两个a元素都具有idhref

    <a id="first_top" href="#first_bottom">Bob</a>
    <a id="first_bottom" href="#first_top">Bob</a>
    
    
    
    编写XSLT代码的一种方法是使用两个模板匹配people元素,但使用mode属性来区分它们

    例如,试试这个XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="html" indent="yes"/>
       <xsl:template match="/people">
          <html>
             <body>
                <xsl:apply-templates select="person" mode="top"/>
                <p>
                   Some content in the middle
                </p>
                <xsl:apply-templates select="person" mode="bottom"/>
             </body>
          </html>
       </xsl:template>
    
       <xsl:template match="person" mode="top">
          <p>
             <a id="{@id}_top" href="#{@id}_bottom">
                <xsl:value-of select="name" />
             </a>
          </p>
       </xsl:template>
    
       <xsl:template match="person" mode="bottom">
          <p>
             <a id="{@id}_bottom" href="#{@id}_top">
                <xsl:value-of select="name" />
             </a>
          </p>
       </xsl:template>
    </xsl:stylesheet>
    
    
    
    中间内容
    

    这将输出以下内容(假设您有一个具有根元素的格式良好的XML,并且所有标记都已关闭)

    
    

    中间有一些内容

    如果希望避免使用两个单独的模板来匹配person元素,可以将参数传递给模板以区分顶部和底部。这个XSLT也可以工作

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="html" indent="yes"/>
       <xsl:template match="/people">
          <html>
             <body>
                <xsl:apply-templates select="person">
                    <xsl:with-param name="idpos" select="'top'" />
                    <xsl:with-param name="hrefpos" select="'bottom'" />
                </xsl:apply-templates>
                <p>
                   Some content in the middle
                </p>
                <xsl:apply-templates select="person">
                    <xsl:with-param name="idpos" select="'bottom'" />
                    <xsl:with-param name="hrefpos" select="'top'" />
                </xsl:apply-templates>
             </body>
          </html>
       </xsl:template>
    
       <xsl:template match="person">
          <xsl:param name="idpos" />
          <xsl:param name="hrefpos" />
          <p>
             <a id="{@id}_{$idpos}" href="#{@id}_{$hrefpos}">
                <xsl:value-of select="name" />
             </a>
          </p>
       </xsl:template>
    </xsl:stylesheet>
    
    
    
    中间内容
    


    如果要导航到页面中的锚定标记,则需要将href属性设置为适当值的另一个链接。例如,如果锚定标记为:

    <a id="first">Bob</a>
    
    
    
    在您的情况下,您希望锚定彼此链接,因此两个a元素都具有idhref

    <a id="first_top" href="#first_bottom">Bob</a>
    <a id="first_bottom" href="#first_top">Bob</a>
    
    
    
    编写XSLT代码的一种方法是使用两个模板匹配people元素,但使用mode属性来区分它们

    例如,试试这个XSLT

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="html" indent="yes"/>
       <xsl:template match="/people">
          <html>
             <body>
                <xsl:apply-templates select="person" mode="top"/>
                <p>
                   Some content in the middle
                </p>
                <xsl:apply-templates select="person" mode="bottom"/>
             </body>
          </html>
       </xsl:template>
    
       <xsl:template match="person" mode="top">
          <p>
             <a id="{@id}_top" href="#{@id}_bottom">
                <xsl:value-of select="name" />
             </a>
          </p>
       </xsl:template>
    
       <xsl:template match="person" mode="bottom">
          <p>
             <a id="{@id}_bottom" href="#{@id}_top">
                <xsl:value-of select="name" />
             </a>
          </p>
       </xsl:template>
    </xsl:stylesheet>
    
    
    
    中间内容
    

    这将输出以下内容(假设您有一个具有根元素的格式良好的XML,并且所有标记都已关闭)

    
    

    中间有一些内容

    如果希望避免使用两个单独的模板来匹配person元素,可以将参数传递给模板以区分顶部和底部。这个XSLT也可以工作

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
       <xsl:output method="html" indent="yes"/>
       <xsl:template match="/people">
          <html>
             <body>
                <xsl:apply-templates select="person">
                    <xsl:with-param name="idpos" select="'top'" />
                    <xsl:with-param name="hrefpos" select="'bottom'" />
                </xsl:apply-templates>
                <p>
                   Some content in the middle
                </p>
                <xsl:apply-templates select="person">
                    <xsl:with-param name="idpos" select="'bottom'" />
                    <xsl:with-param name="hrefpos" select="'top'" />
                </xsl:apply-templates>
             </body>
          </html>
       </xsl:template>
    
       <xsl:template match="person">
          <xsl:param name="idpos" />
          <xsl:param name="hrefpos" />
          <p>
             <a id="{@id}_{$idpos}" href="#{@id}_{$hrefpos}">
                <xsl:value-of select="name" />
             </a>
          </p>
       </xsl:template>
    </xsl:stylesheet>
    
    
    
    中间内容
    


    这不一定是XSLT问题,您只需生成适当的
    ,反之亦然。例如,顶部链接可以是

    <xsl:for-each select="person">
      <a id="top_{@id}" href="#bottom_{@id}">
        <xsl:value-of select="name"/>
      </a>
    </xsl:for-each>
    

    这不一定是XSLT问题,您只需生成适当的
    ,反之亦然。例如,顶部链接可以是

    <xsl:for-each select="person">
      <a id="top_{@id}" href="#bottom_{@id}">
        <xsl:value-of select="name"/>
      </a>
    </xsl:for-each>
    
    
    
    如果a)输入的XML格式正确,b)以HTML格式给出预期输出,而不是(或除此之外)对其进行解释,那么您获得答案的几率会高得多,c)将当前XSLT样式表添加到问题中。如果a)输入XML格式正确,b)以HTML格式给出预期输出,而不是(或另外)解释它,以及c)将当前XSLT样式表添加到问题中,则获得答案的几率将大得多。