不知道如何从树中获取值
unable to know how to get the value from tree
我正在编写 XSL,以下是我的要求。
- 每当我遇到
superscript
时,搜索整个 XML 并看到一个带有属性覆盖的列表项,hte 值应该等于 superscript
.
- 如果找到,则应用模板
下面是我的XML
<?xml version="1.0" encoding="UTF-8"?>
<division>
<superscript>1</superscript>
<page num="1"/>
<note role="para-footnote">
<orderedlist>
<listitem override="1">
<para>Hi</para>
</listitem>
</orderedlist>
</note>
</division>
这是我的 XSL
<xsl:template match="superscript[name(ancestor::*[last()]) = 'division']">
<xsl:apply-templates select="//listitem[@override=.]/preceding::page[1]" mode="first"/>
<xsl:variable name="cnt" select="count(preceding::superscript)+1"/>
<xsl:variable name="varHeaderNote" select='concat("f",$cnt)'/>
<xsl:variable name="varFootNote" select='concat("#ftn.",$cnt)'/>
<sup>
<a name="{$varHeaderNote}" href="{$varFootNote}" class="tr_ftn">
<xsl:value-of select="."/>
</a>
</sup>
</xsl:template>
<xsl:template match="page" mode="first">
<xsl:variable name="pb" select="./@num"/>
<xsl:processing-instruction name="pb">
<xsl:text>label='</xsl:text>
<xsl:value-of select="$pb"/>
<xsl:text>'</xsl:text>
<xsl:text>?</xsl:text>
</xsl:processing-instruction>
<a name="{concat('pg_',$pb)}"/>
</xsl:template>
我现在的O/p
<!DOCTYPE html
PUBLIC "XSLT-compat">
<hmtl>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>New Version!</title>
</head>
<sup><a name="f1" href="#ftn.1" class="tr_ftn">1</a></sup>
<page num="1"></page>
<note role="para-footnote">
<orderedlist>
<listitem override="1">
<para>Hi</para>
</listitem>
</orderedlist>
</note>
</hmtl>
预计O/p:
<!DOCTYPE html
PUBLIC "XSLT-compat">
<hmtl>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>New Version!</title>
</head>
<?pb label='1'?>
<sup><a name="f1" href="#ftn.1" class="tr_ftn">1</a></sup>
<page num="1"></page>
<note role="para-footnote">
<orderedlist>
<listitem override="1">
<para>Hi</para>
</listitem>
</orderedlist>
</note>
</hmtl>
这是一个有效的 fiddle。 http://xsltransform.net/ejivdGR
请告诉我哪里出错了,我该如何解决。
谢谢
比较谓词中的@override = current()
,见http://xsltransform.net/ejivdGR/1。
或者最好定义一个键<xsl:key name="li" match="listitem" use="@override"/>
然后你可以使用key('li', .)
找到superscript
引用的listitem
。
我正在编写 XSL,以下是我的要求。
- 每当我遇到
superscript
时,搜索整个 XML 并看到一个带有属性覆盖的列表项,hte 值应该等于superscript
. - 如果找到,则应用模板
下面是我的XML
<?xml version="1.0" encoding="UTF-8"?>
<division>
<superscript>1</superscript>
<page num="1"/>
<note role="para-footnote">
<orderedlist>
<listitem override="1">
<para>Hi</para>
</listitem>
</orderedlist>
</note>
</division>
这是我的 XSL
<xsl:template match="superscript[name(ancestor::*[last()]) = 'division']">
<xsl:apply-templates select="//listitem[@override=.]/preceding::page[1]" mode="first"/>
<xsl:variable name="cnt" select="count(preceding::superscript)+1"/>
<xsl:variable name="varHeaderNote" select='concat("f",$cnt)'/>
<xsl:variable name="varFootNote" select='concat("#ftn.",$cnt)'/>
<sup>
<a name="{$varHeaderNote}" href="{$varFootNote}" class="tr_ftn">
<xsl:value-of select="."/>
</a>
</sup>
</xsl:template>
<xsl:template match="page" mode="first">
<xsl:variable name="pb" select="./@num"/>
<xsl:processing-instruction name="pb">
<xsl:text>label='</xsl:text>
<xsl:value-of select="$pb"/>
<xsl:text>'</xsl:text>
<xsl:text>?</xsl:text>
</xsl:processing-instruction>
<a name="{concat('pg_',$pb)}"/>
</xsl:template>
我现在的O/p
<!DOCTYPE html
PUBLIC "XSLT-compat">
<hmtl>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>New Version!</title>
</head>
<sup><a name="f1" href="#ftn.1" class="tr_ftn">1</a></sup>
<page num="1"></page>
<note role="para-footnote">
<orderedlist>
<listitem override="1">
<para>Hi</para>
</listitem>
</orderedlist>
</note>
</hmtl>
预计O/p:
<!DOCTYPE html
PUBLIC "XSLT-compat">
<hmtl>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>New Version!</title>
</head>
<?pb label='1'?>
<sup><a name="f1" href="#ftn.1" class="tr_ftn">1</a></sup>
<page num="1"></page>
<note role="para-footnote">
<orderedlist>
<listitem override="1">
<para>Hi</para>
</listitem>
</orderedlist>
</note>
</hmtl>
这是一个有效的 fiddle。 http://xsltransform.net/ejivdGR
请告诉我哪里出错了,我该如何解决。
谢谢
比较谓词中的@override = current()
,见http://xsltransform.net/ejivdGR/1。
或者最好定义一个键<xsl:key name="li" match="listitem" use="@override"/>
然后你可以使用key('li', .)
找到superscript
引用的listitem
。