O’Connor v Uber Technols., Inc. (ND Cal, Dec. 05, 2013, No. C–13–3826 EMC) 2013 US Dist Lexis 171813, rev’d on other grounds (9th Cir 2018) 904 F3d 1087:
此行出现两次括号(ND Cal,2013年12月5日,编号C–13 –3826 EMC)和(2018年9月Cir)。我们可以先加上括号吗?并且最后两个条目不能根据最新日期移动后代,因为正则表达式用于日期格式\((.*?)((' || string-join($months, '|') || ')\. ([0-9]{1,2}), ([0-9]{4})).*?\)
输入XML
<root>
<p content-type="emCase"><named-content content-type="emEntry">AFL-CIO v Unemployment Ins. Appeals Bd. (1994) 23 CA4th 51:</named-content></p>
<p content-type="emCase"><named-content content-type="emEntry">AFL-CIO v Unemployment Ins. Appeals Bd. (1996) 13 C4th 1017:</named-content></p>
<p content-type="emCase"><named-content content-type="emEntry">Ambat v City & County of San Francisco (ND Cal 2010) 693 F Supp 2d 1130, rev’d on other grounds (9th Cir 2014) 757 F3d 1017:</named-content></p>
<p content-type="emCase"><named-content content-type="emEntry">Ambat v City & County of San Francisco (9th Cir 2014) 757 F3d 1017:</named-content></p>
<p content-type="emCase"><named-content content-type="emEntry">Anaheim Union High Sch. Dist. (2016) PERB Dec. No. 2504E, 41 PERC 80:</named-content></p>
<p content-type="emCase"><named-content content-type="emEntry">Anaheim Union High Sch. Dist. (1981) PERB Dec. No. 0177E, 5 PERC 12148:</named-content></p>
<p content-type="emCase"><named-content content-type="emEntry">Artec Group v Klimov (ND Cal, Nov. 22, 2015) 2015 US Dist Lexis 171698:</named-content></p>
<p content-type="emCase"><named-content content-type="emEntry">Artec Group v Klimov (ND Cal, Dec. 22, 2015) 2016 US Dist Lexis 170194:</named-content></p>
<p content-type="emCase"><named-content content-type="emEntry">O’Connor v Uber Technols., Inc. (ND Cal, Dec. 05, 2013, No. C–13–3826 EMC) 2013 US Dist Lexis 171813, rev’d on other grounds 904 F3d 1087:</named-content></p>
<p content-type="emCase"><named-content content-type="emEntry">O’Connor v Uber Technols., Inc. (2018) 904 F3d 1087:</named-content></p>
<p content-type="emCase"><named-content content-type="emEntry">O’Connor v Uber Technols., Inc. (ND Cal 2015) 82 F Supp 3d 1133:</named-content></p>
<p content-type="emCase"><named-content content-type="emEntry">Swarmfly, Inc. v Cloudflare, Inc. (ND Cal, May 31, 2018, No. C 17-06957 WHA) 2018 US Dist Lexis 91333:</named-content></p>
<p content-type="emCase"><named-content content-type="emEntry">Swarmify, Inc. v Cloudflare, Inc. (ND Cal, Sept. 28, 2018, No. C 17-06957 WHA) 2018 US Dist Lexis 168317:</named-content></p>
<p content-type="emCase"><named-content content-type="emEntry">Swarmify, Inc. v Cloudflare, Inc. (ND Cal, Mar. 3, 2018, No. C 17-06597 WHA) 2018 WL 112204:</named-content></p>
<p content-type="emCase"><named-content content-type="emEntry">Zody v Microsoft Corp. (ND Cal, June 7, 2013, No. C–12–00942–YGR) 2013 US Dist Lexis 80623:</named-content></p>
<p content-type="emCase"><named-content content-type="emEntry">Zody v Microsoft Corp. (ND Cal, July 24, 2013, No. C–12–00942–YGR) 2013 US Dist Lexis 103868:</named-content></p>
</root>
XSLT
<xsl:param name="months" as="xs:string*"
select="'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec'"/>
<xsl:param name="date-pattern" as="xs:string"
select="'\((.*?)((' || string-join($months, '|') || ')\. ([0-9]{1,2}), ([0-9]{4})).*?\)'"/>
<xsl:output indent="yes"/>
<xsl:template match="@specific-use|named-content[@content-type='emSecs']"/>
<xsl:function name="mf:extract-date" as="xs:date?">
<xsl:param name="input" as="xs:string"/>
<xsl:sequence
select="let $match := analyze-string($input, $date-pattern)/*:match[1]
return
if ($match)
then xs:date(
$match//*:group[@nr = 5]
|| '-' || format-integer(index-of($months, $match//*:group[@nr = 3]), '00')
|| '-' || format-integer($match//*:group[@nr = 4], '00'))
else ()"/>
</xsl:function>
<xsl:function name="mf:extract-year" as="xs:integer?">
<xsl:param name="input" as="xs:string"/>
<xsl:sequence
select="analyze-string($input, '\((.*?)([0-9]{4})\)')/*:match[1]/*:group[@nr = 2]"/>
</xsl:function>
<xsl:function name="mf:extract-sort" as="xs:string?">
<xsl:param name="input" as="xs:string"/>
<xsl:sequence
select="analyze-string($input, '\((.*?)\)')/*:match[1]/*:group[@nr = 1]"/>
</xsl:function>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="root">
<xsl:copy>
<xsl:for-each-group select="p" group-adjacent="substring-before(named-content[@content-type = 'emEntry'], '(')">
<xsl:apply-templates select="current-group()">
<xsl:sort select="let $year := mf:extract-year(.)
return if ($year) then -$year else 1"/>
<xsl:sort select="let $date := mf:extract-date(.)
return if (exists($date)) then $date else 1" order="descending"/>
<xsl:sort select="let $sort := mf:extract-sort(.)
return if ($sort) then $sort else 1" order="descending"/>
</xsl:apply-templates>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
预期输出
<root>
<p content-type="emCase">
<named-content content-type="emEntry">AFL-CIO v Unemployment Ins. Appeals Bd. (1996) 13 C4th 1017:</named-content>
</p>
<p content-type="emCase">
<named-content content-type="emEntry">AFL-CIO v Unemployment Ins. Appeals Bd. (1994) 23 CA4th 51:</named-content>
</p>
<p content-type="emCase">
<named-content content-type="emEntry">Ambat v City & County of San Francisco (9th Cir 2014) 757 F3d 1017:</named-content>
</p>
<p content-type="emCase">
<named-content content-type="emEntry">Ambat v City & County of San Francisco (ND Cal 2010) 693 F Supp 2d 1130, rev’d on other grounds (9th Cir 2014) 757 F3d 1017:</named-content>
</p>
<p content-type="emCase">
<named-content content-type="emEntry">Anaheim Union High Sch. Dist. (2016) PERB Dec. No. 2504E, 41 PERC 80:</named-content>
</p>
<p content-type="emCase">
<named-content content-type="emEntry">Anaheim Union High Sch. Dist. (1981) PERB Dec. No. 0177E, 5 PERC 12148:</named-content>
</p>
<p content-type="emCase">
<named-content content-type="emEntry">Artec Group v Klimov (ND Cal, Dec. 22, 2015) 2016 US Dist Lexis 170194:</named-content>
</p>
<p content-type="emCase">
<named-content content-type="emEntry">Artec Group v Klimov (ND Cal, Nov. 22, 2015) 2015 US Dist Lexis 171698:</named-content>
</p>
<p content-type="emCase">
<named-content content-type="emEntry">O’Connor v Uber Technols., Inc. (2018) 904 F3d 1087:</named-content>
</p>
<p content-type="emCase">
<named-content content-type="emEntry">O’Connor v Uber Technols., Inc. (ND Cal 2015) 82 F Supp 3d 1133:</named-content>
</p>
<p content-type="emCase">
<named-content content-type="emEntry">O’Connor v Uber Technols., Inc. (ND Cal, Dec. 05, 2013, No. C–13–3826 EMC) 2013 US Dist Lexis 171813, rev’d on other grounds (9th Cir 2018) 904 F3d 1087:</named-content>
</p>
<p content-type="emCase">
<named-content content-type="emEntry">Swarmify, Inc. v Cloudflare, Inc. (ND Cal, Sept. 28, 2018, No. C 17-06957 WHA) 2018 US Dist Lexis 168317:</named-content>
</p>
<p content-type="emCase">
<named-content content-type="emEntry">Swarmfly, Inc. v Cloudflare, Inc. (ND Cal, May 31, 2018, No. C 17-06957 WHA) 2018 US Dist Lexis 91333:</named-content>
</p>
<p content-type="emCase">
<named-content content-type="emEntry">Swarmify, Inc. v Cloudflare, Inc. (ND Cal, Mar. 3, 2018, No. C 17-06597 WHA) 2018 WL 112204:</named-content>
</p>
<p content-type="emCase">
<named-content content-type="emEntry">Zody v Microsoft Corp. (ND Cal, July 24, 2013, No. C–12–00942–YGR) 2013 US Dist Lexis 103868:</named-content>
</p>
<p content-type="emCase">
<named-content content-type="emEntry">Zody v Microsoft Corp. (ND Cal, June 7, 2013, No. C–12–00942–YGR) 2013 US Dist Lexis 80623:</named-content>
</p>
</root>
:https://xsltfiddle.liberty-development.net/pNmC4Jf/19 如何解决排序时发现的不可比较类型:无法将xs:date与xs:integer比较这行显示错误O'Connor v Uber Technols。,Inc.(ND Cal,2013年12月5日,编号C。 ..CODE
let $date := mf:extract-date(.) return if (exists($date)) then $date else 1
可能是罪魁祸首,您将需要使用一些默认的xs:date
,不确定要使用哪个基准日期,但是可以使用例如else xs:date('1900-01-01')
。