我有下面的 XML。当我运行 XSLT 时,输出与预期不同。
<toc><tertiaryie>generally, 75/24—75/24/1</tertiaryie>
<secondaryie>Practice Direction, PD1.1/1—PD1.1/9</secondaryie>
<secondaryie>preliminary act</secondaryie>
<secondaryie>collision actions, 75/20</secondaryie>
<secondaryie>failure to lodge, E75/19/32</secondaryie>
</toc>
当我尝试应用以下 xslt.
<xsl:template match="tertiaryie">
<xsl:variable name="tertClassType">
<xsl:value-of select="@level"/>
</xsl:variable>
<xsl:variable name="tertClassTypName">
<xsl:value-of select="concat('tertiaryie-', $tertClassType)"/>
</xsl:variable>
<div class="tertiaryie">
<xsl:apply-templates/>
</div>
</xsl:template>
<xsl:template match="text()">
<xsl:analyze-string select="." regex="[^,\s—[A-Z]+]+">
<xsl:matching-substring>
<xsl:variable name="range" select="tokenize(.,'—')"/>
<xsl:variable name="pg" select="tokenize(.,'/')"/>
<xsl:choose>
<xsl:when test="not(contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ',substring(.,1,1)))">
<xsl:choose>
<xsl:when test="contains($pg[3],'—')">
<xsl:variable name="range-pg" as="item()*">
<xsl:for-each select="$range">
<xsl:sequence select="tokenize(.,'/')"/>
</xsl:for-each>
</xsl:variable>
<xsl:for-each select="xs:integer($range-pg[3]) to xs:integer($range-pg[6])">
<a href="er:#HKWBV1_ORD_{
if (string(number($range-pg[1]))!='NaN') then
format-number(number($range-pg[1]),'00')
else
$range-pg[1]}/P{string-join($range-pg[position()=(1,2)],'/')}/{.}">
<xsl:value-of select="concat(string-join($range-pg[position()=(1,2)],'/'),'/',.)"/>
</a>
<xsl:text>, </xsl:text>
</xsl:for-each>
</xsl:when>
<xsl:otherwise>
<a href="er:#HKWBV1_ORD_{
if (string(number($pg[1]))!='NaN') then
format-number(number($pg[1]),'00')
else
$pg[1]}/P{$pg[1]
}/{string-join($pg[position()>1],'/')}">
<xsl:value-of select="."/>
</a>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="contains('PD',substring(.,1,2))">
<a href="{concat('HKWBV1_SEC_',substring-after(substring-before(.,'/'),'PD'),'/PPD',translate(substring-after(.,'PD'),'.','-'))}">
<xsl:value-of select="."/>
</a>
</xsl:when>
<xsl:otherwise>
<span class="invalid">
<xsl:value-of select="."/>
</span>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
它给了我以下输出。
<div class="tertiaryie"><a href="er:#HKWBV1_ORD_generally/Pgenerally/">generally</a>, <a href="er:#HKWBV1_ORD_75/P75/24">75/24</a>—<a href="er:#HKWBV1_ORD_75/P75/24/1">75/24/1</a></div>
我想要的输出如下。
<div class="tertiaryie">generally, <a href="er:#HKWBV1_ORD_75/P75/24">75/24</a>—<a href="er:#HKWBV1_ORD_75/P75/24/1">75/24/1</a></div>
请让我知道我怎样才能得到这个。这里所有的文本也都被引用了,因为我只想要数字来获得引用。