【问题标题】:create a link with xslt in html to other html使用 html 中的 xslt 创建到其他 html 的链接
【发布时间】:2013-08-04 14:06:46
【问题描述】:

我有以下 xml 代码:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml"
        schematypens="http://purl.oclc.org/dsdl/schematron"?>
<TEI xmlns="http://www.tei-c.org/ns/1.0">
    <teiHeader/>
    <text>
        <head n="3">Capitulo primeyro</head>
        <pb facs="folio16r.jpg"/>
        <div>
            <p>... figurado <app>
                <lem>pollo</lem>
                <rdg wit="#A">pollo</rdg>
                <rdg wit="#B">pello</rdg>
            </app> Parayso ...</p>
            <p> ... <app>
                <lem>sacarõ</lem>
                <rdg wit="#A">sacarõ</rdg>
                <rdg wit="#B">ssaee</rdg>
                </app> ...</p>
        </div>
        <pb facs="folio16v.jpg"/>
        <div>
            <p> .... os fisicos <app>
                <lem>dessesperarom</lem>
                <rdg wit="#A">desseperarom</rdg>
                <rdg wit="#B">desesperõ</rdg>
                </app> ... que assy <app>
                <lem>saa</lem>
                <rdg wit="#A">sooa</rdg>
                <rdg wit="#B">saa</rdg>
                </app> ...</p>
        </div>
    </body>
</text>

使用我的 XSL,我已经获得了 3 种不同的 HTML(一种用于 A,一种用于 B,一种用于引理)。我在 XSL 中为应用创建了一个模板:

<xsl:template match="app">
    <xsl:variable name="appNumber" select="count(preceding::app) + 1"/>
    <a href="#app_{$appNumber}"><xsl:apply-templates select="lem"/></a>
</xsl:template>

<xsl:template match="app" mode="footnote">
    <xsl:variable name="appNumber" select="count(preceding::app) + 1"/>
    <li id="app_{$appNumber}">
        <xsl:for-each select="rdg">
            <i><xsl:apply-templates/></i><xsl:text> </xsl:text>
            <a>
                <xsl:attribute name="href">
                    <xsl:text>#</xsl:text>
                    <xsl:apply-templates select="app"/>
                </xsl:attribute>
                <xsl:value-of select="substring-after(@wit, '#')">
                </xsl:value-of>
            </a>
            <xsl:text> </xsl:text>
            <br/>
            <xsl:if test="position() lt last()"></xsl:if>
        </xsl:for-each>
    </li>
</xsl:template>

现在我有了这个 html:

<ul>
    <li id="app_1"><i>prophetas</i> <a href="#">Editor</a> <br /><i>prophetas</i> <a href="#">A</a> <br /></li>
    <li id="app_2"><i>pollo</i> <a href="#">Editor</a> <br /><i>pollo</i> <a href="#">A</a> <br /></li>
    <li id="app_3"><i>sacarõ</i> <a href="#">Editor</a> <br /><i>sacarõ</i> <a href="#">A</a> <br /></li>
    <li id="app_4"><i>dessesperarom</i> <a href="#">Editor</a> <br /><i>desseperarom</i> <a href="#">A</a> <br /></li>
    <li id="app_5"><i>saa</i> <a href="#">Editor</a> <br /><i>sooa</i> <a href="#">A</a> <br /></li>
    <li id="app_6"><i>ante</i> <a href="#">Editor</a> <br /><i>ante</i> <a href="#">A</a> <br /></li>
</ul>

如您所见,开始在 li 中创建链接,但我没有得到我想要的。我想说链接从机智(#A 或 #B 或 #Editor)到另一个 html 中的同一文本点。例如,如果我正在查看 A html,在应用程序中,单击 B 我想转到 B html 中的同一文本点。有人可以帮忙吗?

【问题讨论】:

  • 你的解释很混乱。写下你想得到的 HTML 怎么样?
  • 另外,虽然没有大型 XML 样本总是好的,但我认为您在这里展示的不够充分,因为您当前的输出与当前输入不对应。看起来您的输入 XML 应该有六个 app 元素,其中包含与您向我们展示的内容不同的文本。如果您可以显示您当前用于获取当前输出的 XML,那也会有很大帮助。谢谢!
  • 亲爱的 Tim C,我展示了这一切。谢谢

标签: xml xslt hyperlink tei


【解决方案1】:

如果我做对了,这只是关于链接的正确组成。似乎您有一个设备文件,该文件应链接到每个设备条目上的不同源文件。其实,你们已经很亲近了。试试这个:

<xsl:attribute name="href">
    <xsl:value-of select="substring-after(@wit, '#')"/>
    <xsl:text>.html#app_</xsl:text>
    <xsl:value-of select="$appNumber"/>
    <xsl:apply-templates select="app"/>
</xsl:attribute>

这将产生如下链接:

<a href="A.html#app_2">A</a>

我假设您一直以来都已经自己弄清楚了。尽管如此,我还是想回答这个问题,也许它对某人仍然有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-22
    • 2018-07-11
    相关资源
    最近更新 更多