0

我真的为这个挠头。我想创建一个带有来自 XML 摘录的超链接的项目符号列表。我可以创建项目符号列表,但我不知道如何将部分组合在一起。

这是 XML:

<list>
    <listitem>1<hyperlink><url>page1.xml</url><name>Go to Page 1</name></hyperlink></listitem>
    <listitem>2<hyperlink><url>page2.xml</url><name>Go to Page 2</name></hyperlink></listitem>
    <listitem>3<hyperlink><url>page3.xml</url><name>Go to Page 3</name></hyperlink></listitem>
    <listitem>4<hyperlink><url>page4.xml</url><name>Go to Page 4</name></hyperlink></listitem>
</list>

...以及到目前为止的 XSL。超链接组件不起作用。通过我尝试使其工作,它可能看起来有点不整洁。我希望“转到第 n 页”成为超链接。

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/REC-html40">


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

<xsl:template match="list">
    <DIV>
        <UL><xsl:apply-templates /></UL>
    </DIV>
</xsl:template>

<xsl:template match="listitem">
    <DIV>
        <LI><xsl:apply-templates />  </LI>
    </DIV>
</xsl:template>

<xsl:template match="hyperlink">
        <A>
            <xsl:value-of select="hyperlink" />
        </A>
</xsl:template>

<xsl:template match="hyperlink/url">
         HREF='<xsl:value-of select="url" />'  
</xsl:template>

<xsl:template match="hyperlink/name">
         <xsl:apply-templates />
</xsl:template>

目前的结果是:

**1。HREF='page1.xml' 转到第 1 页

  1. HREF='page2.xml' 转到第 2 页

  2. HREF='page3.xml' 转到第 3 页

  3. HREF='page4.xml' 转到第 4 页 **

我需要的是类似于这样的HTML:

<A HREF='page1.xml'>Go to Page 1</A>

任何帮助表示赞赏!

4

1 回答 1

0

首先,您需要DIV从模板中取出listitem(因为LI需要直接在 内结束UL),您可以将所有hyperlink内容简化为一个模板

<xsl:template match="hyperlink">
  <A href="{url}">
    <xsl:value-of select="name"/>
  </A>
</xsl:template>
于 2013-03-21T18:35:32.780 回答