Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果起始文本“(^U.S.ex rel)|(^Will of))”包含文本“v”,则如何在“v”之前添加文本-XSLT_Xslt_Xslt 2.0 - Fatal编程技术网

如果起始文本“(^U.S.ex rel)|(^Will of))”包含文本“v”,则如何在“v”之前添加文本-XSLT

如果起始文本“(^U.S.ex rel)|(^Will of))”包含文本“v”,则如何在“v”之前添加文本-XSLT,xslt,xslt-2.0,Xslt,Xslt 2.0,如果开始文本^U.S.ex rel | ^将包含文本v,那么如何在v文本之前插入开始文本^U.S.ex rel | ^将以其他方式插入文本结尾? 输入XML 预期产量 预期产出 代码:-尝试是否 <xsl:param name="pattern1" as="xs:string">((^U\.S\. ex rel )|(^Will of ))</xsl:param> <xsl:param name="pattern2" as="xs:string">([^v]

如果开始文本^U.S.ex rel | ^将包含文本v,那么如何在v文本之前插入开始文本^U.S.ex rel | ^将以其他方式插入文本结尾? 输入XML

预期产量

预期产出

代码:-

尝试是否

<xsl:param name="pattern1" as="xs:string">((^U\.S\. ex rel )|(^Will of ))</xsl:param>

<xsl:param name="pattern2" as="xs:string">([^v]*?)( v.*)</xsl:param>

<xsl:param name="pattern3" as="xs:string" select="$pattern1 || $pattern2"/>

<xsl:output method="xml"/>

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="italic">
    <xsl:value-of select="replace(., $pattern1 || '(.*)', '$4, $2$3')"/>
</xsl:template>

<xsl:template match="italic[matches(., $pattern3)]">
    <xsl:value-of select="replace(., $pattern3, '$4, $2$3$5')"/>
</xsl:template>
帮助:

您可能需要规范化修复模式的替换结果。另外| |是XPath 3.1,请对XPath/XSLT 2.0使用concat函数

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="italic">
    <xsl:analyze-string select="." regex="((^U.S. ex rel )|(^Will of ))(.+)">
        <xsl:matching-substring>
            <xsl:value-of select="normalize-space(concat(regex-group(4), ', ', regex-group(1)))"/>
        </xsl:matching-substring>
        <xsl:non-matching-substring>
            <xsl:value-of select="."/>
        </xsl:non-matching-substring>
    </xsl:analyze-string>
</xsl:template>
 <root>
    <p>Alcohol Found., U.S. ex rel v Kalmanovitz (SD NY 2002) 186 F Supp 2d 458</p>
    <p>Guardiola, U.S. ex rel v Renown Health (D Nev, Aug. 25, 2015, No. 3:12–cv–00295-LRH-VPC) 2015 US Dist Lexis 112511</p>
    <p>Guardiola Renown Health, Will of (D Nev, Aug. 25, 2015, No. 3:12–cv–00295-LRH-VPC) 2015 US Dist Lexis 112511</p>
</root>
<xsl:param name="pattern1" as="xs:string">((^U\.S\. ex rel )|(^Will of ))</xsl:param>

<xsl:param name="pattern2" as="xs:string">([^v]*?)( v.*)</xsl:param>

<xsl:param name="pattern3" as="xs:string" select="$pattern1 || $pattern2"/>

<xsl:output method="xml"/>

<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="italic">
    <xsl:value-of select="replace(., $pattern1 || '(.*)', '$4, $2$3')"/>
</xsl:template>

<xsl:template match="italic[matches(., $pattern3)]">
    <xsl:value-of select="replace(., $pattern3, '$4, $2$3$5')"/>
</xsl:template>