在Regex中调用另一个模板
我有下面的一段XML在Regex中调用另一个模板,regex,xslt-2.0,Regex,Xslt 2.0,我有下面的一段XML <title>Conduct of external affairs <content-style font-style="italic">via</content-style> NGOs</title> 我还为内容样式声明了一个模板,但我不知道如何链接它 <xsl:template match="content-style"> <xsl:choose> <xsl:when test="
<title>Conduct of external affairs <content-style font-style="italic">via</content-style> NGOs</title>
我还为内容样式声明了一个模板,但我不知道如何链接它
<xsl:template match="content-style">
<xsl:choose>
<xsl:when test="./@format">
<span class="{concat('format-',@format)}">
<xsl:apply-templates/>
</span>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="fontStyle">
<xsl:value-of select="concat('font-style-',@font-style)"/>
</xsl:variable>
<span class="{$fontStyle}">
<xsl:value-of select="."/>
<xsl:apply-templates select="para"/>
</span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
请告诉我如何解决这个问题
谢谢我建议对匹配的模板使用一致的代码样式,而不是所谓的模板:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="Conjunction">(of)|(to)|(and)|(the)|(for)</xsl:param>
<xsl:template match="title">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="title/text()">
<xsl:value-of select="for $EachToken in tokenize(lower-case(.), ' ')
return
if(matches($EachToken, $Conjunction))
then
$EachToken
else
concat(upper-case(substring($EachToken, 1, 1)), substring($EachToken, 2))"/>
</xsl:template>
<xsl:template match="content-style">
<xsl:variable name="fontStyle" select="concat('font-style-',@font-style)"/>
<span class="{$fontStyle}">
<xsl:value-of select="."/>
<xsl:apply-templates select="para"/>
</span>
</xsl:template>
<xsl:template match="content-style[@format]">
<span class="{concat('format-',@format)}">
<xsl:apply-templates/>
</span>
</xsl:template>
</xsl:stylesheet>
现在是Saxon 9.5转换
<root>
<title>HOW HIGH IS THE “HIGH DEGREE OF AUTONOMY’ OF HONG KONG?</title>
<title>PREPARATION FOR TRANSFER OF SOVEREIGNTY</title>
<title>Conduct of external affairs <content-style font-style="italic">via</content-style> NGOs</title>
</root>
这个“;高度自治’;香港?
主权移交的准备工作
通过非政府组织处理对外事务
进入
香港的“高度自治”有多高?
主权移交的准备工作
通过非政府组织处理对外事务
Hi@Martin这很有魅力。非常感谢你。但是我需要一个小tweek,在你上面给出的模板中,我需要看到第一个字母的大写字母,如果不是的话,它应该是大写的。再次感谢,请看我的问题案例2。我想我们目前拥有的代码将转变为主权移交做准备。为了
主权移交的准备
所以移交
的t
被转换为t
。还缺少什么?很抱歉输入错误,我现在已经更新了,实际上我需要将主权移交的准备
转换为主权移交的准备
,但没有W转换为<代码>主权转移的准备>代码> >代码>香港的X.2019;高度自治性和X2019;不正确转换。现在,当我用SAXON 9.5转换<代码>准备主权转移<代码>时,我得到了<>代码>主权转让<代码> >代码> >香港X201C的高度是什么?高度自治性和X2019;和/或代码>你首先需要告诉我们你想要的结果和你目前得到的结果。嗨,马丁。对不起。对于延迟回答,我希望输出是<代码>香港的“高度自治”有多高?<代码>
<title>IS HONG KONG AN INTERNATIONAL PERSON?</title>
<title>PREPARATION FOR TRANSFER OF SOVEREIGNTY</title>
Preperation for Transfer of Sovereignty
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="Conjunction">(of)|(to)|(and)|(the)|(for)</xsl:param>
<xsl:template match="title">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="title/text()">
<xsl:value-of select="for $EachToken in tokenize(lower-case(.), ' ')
return
if(matches($EachToken, $Conjunction))
then
$EachToken
else
concat(upper-case(substring($EachToken, 1, 1)), substring($EachToken, 2))"/>
</xsl:template>
<xsl:template match="content-style">
<xsl:variable name="fontStyle" select="concat('font-style-',@font-style)"/>
<span class="{$fontStyle}">
<xsl:value-of select="."/>
<xsl:apply-templates select="para"/>
</span>
</xsl:template>
<xsl:template match="content-style[@format]">
<span class="{concat('format-',@format)}">
<xsl:apply-templates/>
</span>
</xsl:template>
</xsl:stylesheet>
<?xml version='1.0'?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="Conjunction">^(of|to|and|the|for)$</xsl:param>
<xsl:template match="title">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="title/text()">
<xsl:analyze-string select="." regex="(\w)(\w*)">
<xsl:matching-substring>
<xsl:value-of
select="if (matches(., $Conjunction, 'i'))
then lower-case(.)
else concat(upper-case(regex-group(1)), lower-case(regex-group(2)))"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<xsl:value-of select="."/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
<xsl:template match="content-style">
<xsl:variable name="fontStyle" select="concat('font-style-',@font-style)"/>
<span class="{$fontStyle}">
<xsl:apply-templates/>
</span>
</xsl:template>
<xsl:template match="content-style[@format]">
<span class="{concat('format-',@format)}">
<xsl:apply-templates/>
</span>
</xsl:template>
</xsl:stylesheet>
<root>
<title>HOW HIGH IS THE “HIGH DEGREE OF AUTONOMY’ OF HONG KONG?</title>
<title>PREPARATION FOR TRANSFER OF SOVEREIGNTY</title>
<title>Conduct of external affairs <content-style font-style="italic">via</content-style> NGOs</title>
</root>
<title>How High Is the “High Degree of Autonomy’ of Hong Kong?</title>
<title>Preparation for Transfer of Sovereignty</title>
<title>Conduct of External Affairs <span class="font-style-italic">via</span> Ngos</title>