我想选择前的字符串的函数“:”还是像第一次)在XSLT的功能(选择之前串“:”还是像第一个()的XSLT
我输入的是
<E T="B">1.1.1-CES: Describe the normal anatomy.</E>
预期输出是
<span class="emph_B">
<span class="emph_Bcol">1.1.1-CES:</span>
Describe the normal anatomy.
</span>
我有麻烦:)
之前选择的第一个字符串即 (1.1.1-CES 210目前做好以下工作:
<xsl:template match="E">
<span>
<xsl:attribute name="class">emph_I</xsl:attribute>
<xsl:if test="contains(.,':')">
<xsl:variable name="token" select="tokenize(.,': ')[last()]"/>
<xsl:value-of select="$token"/>
<xsl:variable name="seprate"
select="translate(current(),$token,'')"/>
<xsl:value-of select="$seprate"/>
</xsl:if>
<xsl:apply-templates />
</span>
</xsl:template>
我得到的输出
<div class="P"><img class="rarr" src="images/FFU1.gif"></img><span class="emph_I">Describe the
normal c anatomy.111-CES:1.1.1-CES: Describe the
normal anatomy.</span></div>
是有这样的函数第一个()或()之前,像去年()的XSLT?
代码:
<xsl:template match="/">
<xsl:apply-templates select="//CHAPTER" />
</xsl:template>
<xsl:template match="CHAPTER">
<xsl:result-document href="{$pDest}chapter{position()}.xhtml">
<xsl:text disable-output-escaping='yes'><!DOCTYPE HTML></xsl:text>
<html>
<head>
<title>
<xsl:value-of select="CHSO/THD/HD" />
</title>
<link rel="stylesheet" type="text/css" href="styles/stylesheet.css" />
</head>
<body>
<div>
<xsl:attribute name="class">CHAPTER</xsl:attribute>
<div>
<xsl:attribute name="class">CHSO</xsl:attribute>
<div>
<xsl:attribute name="class">THD box-style</xsl:attribute>
<div>
<xsl:attribute name="class">HNUM</xsl:attribute>
<xsl:attribute name="style">text-align:center;color:white;</xsl:attribute>
<xsl:value-of select="CHSO/THD/HNUM" />
</div>
<div>
<xsl:attribute name="class">HD</xsl:attribute>
<xsl:attribute name="style">text-align:center;color:white;</xsl:attribute>
<xsl:value-of select="CHSO/THD/HD" />
</div>
</div>
</div>
<xsl:apply-templates />
</div>
</body>
</html>
</xsl:result-document>
</xsl:template>
<xsl:template match="TBD">
<div>
<xsl:attribute name="class">TBD</xsl:attribute>
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="TLV1">
<div>
<xsl:attribute name="class">TLV1</xsl:attribute>
<xsl:variable name="chapVal" select="tokenize(../../@CHAN,'-')[last()]" />
<xsl:variable name="myId"
select="translate($chapVal,translate($chapVal, '1234567890', ''),'')" />
<xsl:variable name="tlvId" select="translate(./@ID, '.', '-')" />
<h2>
<xsl:attribute name="class">HD</xsl:attribute>
<xsl:attribute name="id">ch<xsl:value-of
select="$myId" />-<xsl:value-of select="$tlvId" />
</xsl:attribute>
<xsl:attribute name="style">margin-bottom:0.5em;</xsl:attribute>
<xsl:value-of select="HD" />
</h2>
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="P">
<div>
<xsl:attribute name="class">P</xsl:attribute>
<xsl:apply-templates />
</div>
</xsl:template>
<xsl:template match="FILE">
<img>
<xsl:attribute name="class">rarr</xsl:attribute>
<xsl:attribute name="src">images/<xsl:value-of
select="@NAME" />
</xsl:attribute>
</img>
</xsl:template>
<xsl:template match="E">
<span>
<xsl:attribute name="class">emph_I</xsl:attribute>
<xsl:if test="contains(.,':')">
<xsl:variable name="token" select="tokenize(.,': ')[last()]"/>
<xsl:value-of select="$token"/>
<xsl:variable name="seprate" select="translate(current(),$token,'')"/>
<xsl:value-of select="$seprate"/>
</xsl:if>
<xsl:apply-templates />
</span>
</xsl:template>
<xsl:template match="LK">
<a>
<xsl:attribute name="class">LK</xsl:attribute>
<xsl:variable name="chapVal"
select="tokenize(../../../../@CHAN,'-')[last()]" />
<xsl:variable name="myId"
select="translate($chapVal,translate($chapVal, '1234567890', ''),'')" />
<xsl:attribute name="href">chapter<xsl:value-of
select="$myId" />.xhtml#<xsl:value-of select="@IDREF" />
</xsl:attribute>
<xsl:apply-templates />
</a>
</xsl:template>
<xsl:template match="SIDEBAR/TLV1">
<div>
<xsl:attribute name="class">SIDEBAR <xsl:value-of
select="@CLASSF" /></xsl:attribute>
<div>
<xsl:attribute name="class">TLV1</xsl:attribute>
<div>
<xsl:attribute name="class">HD bg-col</xsl:attribute>
<span>
<xsl:attribute name="class">sb-head</xsl:attribute>
<span>
<xsl:attribute name="class">col-auto</xsl:attribute>
<xsl:value-of select="HD"></xsl:value-of>
</span>
</span>
</div>
<xsl:if test="P">
<div>
<xsl:attribute name="class">sb-pad</xsl:attribute>
<xsl:for-each select="P">
<div>
<xsl:attribute name="class">P</xsl:attribute>
<xsl:apply-templates select="ancestor-or-self::text()" />
<xsl:if test="E">
<xsl:for-each select="E">
<span>
<xsl:attribute name="class">emph_Bcol</xsl:attribute>
<xsl:apply-templates select="node()" />
</span>
<xsl:apply-templates select="following-sibling::node()[1]" />
</xsl:for-each>
</xsl:if>
</div>
</xsl:for-each>
</div>
</xsl:if>
</div>
</div>
</xsl:template>
<xsl:template match="FG">
<div>
<xsl:attribute name="class">FG</xsl:attribute>
<xsl:attribute name="id"><xsl:value-of select="@ID"></xsl:value-of>
</xsl:attribute>
<xsl:for-each select="P">
<xsl:if test="FILE">
<img>
<xsl:attribute name="class">center</xsl:attribute>
<xsl:attribute name="src">images/<xsl:value-of
select="FILE/@NAME" />
</xsl:attribute>
</img>
</xsl:if>
<xsl:if test="E">
<div>
<xsl:attribute name="class">caption</xsl:attribute>
<xsl:for-each select="E">
<span>
<xsl:attribute name="class">emph_Bcol</xsl:attribute>
<xsl:apply-templates />
</span>
<xsl:apply-templates select="following-sibling::node()[1]" />
</xsl:for-each>
</div>
</xsl:if>
</xsl:for-each>
</div>
</xsl:template>
<xsl:template match="TB">
<div>
<xsl:attribute name="class">TB</xsl:attribute>
<xsl:attribute name="id"><xsl:value-of select="@ID" /> </xsl:attribute>
<table>
<xsl:attribute name="class">FIGURE</xsl:attribute>
<xsl:attribute name="style">border-collapse:collapse;margin-bottom:1em;</xsl:attribute>
<tr style="background-color:#0768a9;">
<td style="vertical-align:top;" class="FIGURE-COL2" colspan="2">
<span class="emph_B">
<xsl:value-of select="TI/E" />
</span>
<span class="white">
<xsl:value-of select="TI/node()[2]" />
</span>
</td>
</tr>
<xsl:apply-templates />
</table>
</div>
</xsl:template>
<xsl:template match="TI">
</xsl:template>
<xsl:template match="tr">
<tr>
<xsl:apply-templates />
</tr>
</xsl:template>
<xsl:template match="th">
<th>
<xsl:attribute name="style">vertical-align:bottom;text-align:left;</xsl:attribute>
<xsl:attribute name="rowspan">1</xsl:attribute>
<xsl:attribute name="colspan">1</xsl:attribute>
<xsl:choose>
<xsl:when test="contains(., ' ')">
<xsl:value-of select="translate(., ' ', '')" />
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates />
</xsl:otherwise>
</xsl:choose>
</th>
</xsl:template>
<xsl:template match="td">
<td>
<xsl:attribute name="style">vertical-align:top;</xsl:attribute>
<xsl:attribute name="rowspan">1</xsl:attribute>
<xsl:attribute name="colspan">1</xsl:attribute>
<xsl:choose>
<xsl:when test="contains(., ' ')">
<xsl:value-of select="translate(., ' ', '')" />
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="node()[1]" />
</xsl:otherwise>
</xsl:choose>
</td>
</xsl:template>
试图子字符串之前我得到输出为
这回答你的问题,但当然你的实现是另一回事。请发布您的整个XSLT代码。然后,我将能够帮助你。 –