Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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
Xml 使用正则表达式查找围绕节点的特定文本_Xml_Regex_Xslt_Xslt 2.0 - Fatal编程技术网

Xml 使用正则表达式查找围绕节点的特定文本

Xml 使用正则表达式查找围绕节点的特定文本,xml,regex,xslt,xslt-2.0,Xml,Regex,Xslt,Xslt 2.0,我对XSLT非常陌生,而且我不是程序员,所以很抱歉我提出了一个可能很愚蠢的问题 我需要找到一些类似这样的引文: BSK StPO-`<emphasis role="smallcaps">Burger,</emphasis>` Art. 4 N 5 问题在于强调元素:我找不到“绕过”它的方法。我发现了一个类似的问题,并试图将其应用于我的问题,但没有成功。此脚本部分找不到任何引用 这是我代码的一部分$DokumentName引用全局定义的参数。引用中带有罗马数字的部分是可选

我对XSLT非常陌生,而且我不是程序员,所以很抱歉我提出了一个可能很愚蠢的问题

我需要找到一些类似这样的引文:

BSK StPO-`<emphasis role="smallcaps">Burger,</emphasis>` Art. 4 N 5
问题在于强调元素:我找不到“绕过”它的方法。我发现了一个类似的问题,并试图将其应用于我的问题,但没有成功。此脚本部分找不到任何引用

这是我代码的一部分
$DokumentName
引用全局定义的参数。引用中带有罗马数字的部分是可选的:



任何帮助都将不胜感激

正则表达式将与显示的字符串不匹配,因为在有连字符的地方需要空格。看起来像

BSK\s+(\p{L}{2,5})\s+(I|II|III|IV|V|VI|VII)?\p{P}
应该是

BSK\s+(\p{L}{2,5})(\s+(I|II|III|IV|V|VI|VII))?\p{P}

这是最后的工作代码,我忘了简单地添加“mode”-属性,我不得不考虑更多的引用选项,我不得不去掉冗余节点和节点部分

    <xsl:template match="text()[matches(., 'BSK\s+(\p{L}{2,5})(\s+(I|II|III|IV|V|VI|VII))?\p{P}')]" mode="copy-style">
    <xsl:variable name="vCur" select="."/>
    <xsl:variable name="pContent" select="string(.)"/>
    <xsl:analyze-string select="$pContent" regex="BSK\s+(\p{{L}}{{2,5}})(\s+(I|II|III|IV|V|VI|VII))?\p{{P}}" flags="i">
        <xsl:matching-substring>
            <xsl:variable name="figureToTargetId">
             <xsl:choose>
                 <xsl:when test="matches(., '(BSK)\s+(\p{L}{2,5})\s+(I|II|III|IV|V|VI|VII)\p{P}')">                  
                   <xsl:analyze-string select="." regex="(\p{{L}}{{2,5}})\s+(I|II|III|IV|V|VI|VII)">
                    <xsl:matching-substring>
                        <xsl:value-of select="concat('K_BSK_', regex-group(1), regex-group(2), '_', regex-group(1))"/>
                    </xsl:matching-substring>
                  </xsl:analyze-string>
                 </xsl:when>
                 <xsl:when test="matches(., '(BSK)\s+(StPO)\p{P}') ">
                     <xsl:analyze-string select="." regex="(BSK)\s+(\p{{L}}{{2,5}})">
                         <xsl:matching-substring>
                             <xsl:value-of select="concat('K_BSK_STPO-JSTPO_', regex-group(2))"/>
                         </xsl:matching-substring>
                    </xsl:analyze-string>
                 </xsl:when>
                 <xsl:when test="matches(., '(BSK)\s+(JStPO)\p{P}') ">
                     <xsl:analyze-string select="." regex="(BSK)\s+(\p{{L}}{{2,5}})">
                         <xsl:matching-substring>
                             <xsl:value-of select="concat('K_BSK_STPO-JSTPO_', regex-group(2))"/>
                         </xsl:matching-substring>
                    </xsl:analyze-string>
                 </xsl:when>
                 <xsl:when test="matches(., 'BSK\s+(\p{L}{2,5})\p{P}') ">
                     <xsl:analyze-string select="." regex="BSK\s+(\p{{L}}{{2,5}})">
                      <xsl:matching-substring>
                          <xsl:value-of select="concat('K_BSK_', regex-group(1), '_', regex-group(1))"/>
                      </xsl:matching-substring>
                  </xsl:analyze-string>
                </xsl:when>
             </xsl:choose>   
            </xsl:variable>
            <xsl:variable name="figureFromTargetId">
                <xsl:if test="matches($vCur, 'BSK\s+(\p{L}{2,5})(\s+(I|II|III|IV|V|VI|VII))?\p{P}')">
                    <xsl:analyze-string select="string($vCur/following-sibling::emphasis[1]/following-sibling::text()[1])" regex="^,?(\s+Vor)?\s+Art\.(\s+|\p{{Zs}})(\p{{N}}{{1,4}})\s+N(\s+|\p{{Zs}})(\p{{N}}{{1,4}})">
                    <xsl:matching-substring>
                      <xsl:choose>
                          <xsl:when test="contains(., 'Vor')">
                              <xsl:value-of select="concat('_VorArt', regex-group(3), '_', regex-group(5))"/>
                          </xsl:when>
                          <xsl:otherwise>
                              <xsl:value-of select="concat('_Art', regex-group(3), '_', regex-group(5))"/>
                          </xsl:otherwise>
                      </xsl:choose>         
                    </xsl:matching-substring>                      
                 </xsl:analyze-string>
                </xsl:if>
            </xsl:variable>
            <xsl:element name="ref-multi-id">
                <xsl:attribute name="multi-idref">
                    <xsl:value-of select="concat($figureToTargetId, $figureFromTargetId)"/>
                </xsl:attribute>
                <xsl:value-of select="."/>
                <xsl:if test="matches($vCur, 'BSK\s+(\p{L}{2,5})(\s+(I|II|III|IV|V|VI|VII))?\p{P}')">
                    <xsl:apply-templates select="$vCur/following-sibling::emphasis[1]" mode="match"/>                    
                </xsl:if>
                <xsl:analyze-string select="string($vCur/following-sibling::emphasis[1]/following-sibling::text()[1])" regex="(^,?(\s+Vor)?\s+Art\.(\s+|\p{{Zs}})(\p{{N}}{{1,4}})\s+N(\s+|\p{{Zs}})(\p{{N}}{{1,4}}))">
                    <xsl:matching-substring>
                        <xsl:value-of select="regex-group(1)"/>
                    </xsl:matching-substring>                        
                </xsl:analyze-string>
            </xsl:element>

        </xsl:matching-substring>
        <xsl:non-matching-substring>
            <xsl:copy-of select="."/>
        </xsl:non-matching-substring>
     </xsl:analyze-string>         
</xsl:template>
    <xsl:template match="emphasis[@role='smallcaps'][not(preceding-sibling::node()[1][self::text() and matches(., 'BSK\s+(\p{L}{2,5})(\s+(I|II|III|IV|V|VI|VII))?\p{P}')])]" mode="copy-style">
     <xsl:element name="span">
            <xsl:attribute name="class">
                <xsl:value-of select="@role"/>
            </xsl:attribute>
            <xsl:apply-templates/>
        </xsl:element>       
     </xsl:template>
     <xsl:template match="emphasis[@role='smallcaps'][preceding-sibling::node()[1][self::text() and matches(., 'BSK\s+(\p{L}{2,5})(\s+(I|II|III|IV|V|VI|VII))?\p{P}')]]" mode="match">
    <xsl:element name="span">
        <xsl:attribute name="class">
            <xsl:value-of select="@role"/>
        </xsl:attribute>
        <xsl:apply-templates/>
      </xsl:element>       
     </xsl:template>
    <xsl:template mode="copy-style" match="text()[matches(., '^,?(\s+Vor)?\s+Art\.(\s+|\p{Zs})(\p{N}{1,4})\s+N(\s+|\p{Zs})(\p{N}{1,4})') and preceding-sibling::emphasis[@role='smallcaps'][1] and matches(preceding-sibling::emphasis[1]/preceding-sibling::text()[1], 'BSK\s+(\p{L}{2,5})(\s+(I|II|III|IV|V|VI|VII))?\p{P}')]">
     <xsl:variable name="pContent" select="string(.)"/>
     <xsl:analyze-string select="$pContent" regex="^,?(\s+Vor)?\s+Art\.(\s+|\p{{Zs}})(\p{{N}}{{1,4}})\s+N(\s+|\p{{Zs}})(\p{{N}}{{1,4}})">
        <xsl:matching-substring/>
        <xsl:non-matching-substring>
            <xsl:copy-of select="."/>
        </xsl:non-matching-substring>
      </xsl:analyze-string>
     </xsl:template>

    <xsl:template match="text()[matches(., 'BSK\s+(\p{L}{2,5})(\s+(I|II|III|IV|V|VI|VII))?\p{P}')]" mode="copy-style">
    <xsl:variable name="vCur" select="."/>
    <xsl:variable name="pContent" select="string(.)"/>
    <xsl:analyze-string select="$pContent" regex="BSK\s+(\p{{L}}{{2,5}})(\s+(I|II|III|IV|V|VI|VII))?\p{{P}}" flags="i">
        <xsl:matching-substring>
            <xsl:variable name="figureToTargetId">
             <xsl:choose>
                 <xsl:when test="matches(., '(BSK)\s+(\p{L}{2,5})\s+(I|II|III|IV|V|VI|VII)\p{P}')">                  
                   <xsl:analyze-string select="." regex="(\p{{L}}{{2,5}})\s+(I|II|III|IV|V|VI|VII)">
                    <xsl:matching-substring>
                        <xsl:value-of select="concat('K_BSK_', regex-group(1), regex-group(2), '_', regex-group(1))"/>
                    </xsl:matching-substring>
                  </xsl:analyze-string>
                 </xsl:when>
                 <xsl:when test="matches(., '(BSK)\s+(StPO)\p{P}') ">
                     <xsl:analyze-string select="." regex="(BSK)\s+(\p{{L}}{{2,5}})">
                         <xsl:matching-substring>
                             <xsl:value-of select="concat('K_BSK_STPO-JSTPO_', regex-group(2))"/>
                         </xsl:matching-substring>
                    </xsl:analyze-string>
                 </xsl:when>
                 <xsl:when test="matches(., '(BSK)\s+(JStPO)\p{P}') ">
                     <xsl:analyze-string select="." regex="(BSK)\s+(\p{{L}}{{2,5}})">
                         <xsl:matching-substring>
                             <xsl:value-of select="concat('K_BSK_STPO-JSTPO_', regex-group(2))"/>
                         </xsl:matching-substring>
                    </xsl:analyze-string>
                 </xsl:when>
                 <xsl:when test="matches(., 'BSK\s+(\p{L}{2,5})\p{P}') ">
                     <xsl:analyze-string select="." regex="BSK\s+(\p{{L}}{{2,5}})">
                      <xsl:matching-substring>
                          <xsl:value-of select="concat('K_BSK_', regex-group(1), '_', regex-group(1))"/>
                      </xsl:matching-substring>
                  </xsl:analyze-string>
                </xsl:when>
             </xsl:choose>   
            </xsl:variable>
            <xsl:variable name="figureFromTargetId">
                <xsl:if test="matches($vCur, 'BSK\s+(\p{L}{2,5})(\s+(I|II|III|IV|V|VI|VII))?\p{P}')">
                    <xsl:analyze-string select="string($vCur/following-sibling::emphasis[1]/following-sibling::text()[1])" regex="^,?(\s+Vor)?\s+Art\.(\s+|\p{{Zs}})(\p{{N}}{{1,4}})\s+N(\s+|\p{{Zs}})(\p{{N}}{{1,4}})">
                    <xsl:matching-substring>
                      <xsl:choose>
                          <xsl:when test="contains(., 'Vor')">
                              <xsl:value-of select="concat('_VorArt', regex-group(3), '_', regex-group(5))"/>
                          </xsl:when>
                          <xsl:otherwise>
                              <xsl:value-of select="concat('_Art', regex-group(3), '_', regex-group(5))"/>
                          </xsl:otherwise>
                      </xsl:choose>         
                    </xsl:matching-substring>                      
                 </xsl:analyze-string>
                </xsl:if>
            </xsl:variable>
            <xsl:element name="ref-multi-id">
                <xsl:attribute name="multi-idref">
                    <xsl:value-of select="concat($figureToTargetId, $figureFromTargetId)"/>
                </xsl:attribute>
                <xsl:value-of select="."/>
                <xsl:if test="matches($vCur, 'BSK\s+(\p{L}{2,5})(\s+(I|II|III|IV|V|VI|VII))?\p{P}')">
                    <xsl:apply-templates select="$vCur/following-sibling::emphasis[1]" mode="match"/>                    
                </xsl:if>
                <xsl:analyze-string select="string($vCur/following-sibling::emphasis[1]/following-sibling::text()[1])" regex="(^,?(\s+Vor)?\s+Art\.(\s+|\p{{Zs}})(\p{{N}}{{1,4}})\s+N(\s+|\p{{Zs}})(\p{{N}}{{1,4}}))">
                    <xsl:matching-substring>
                        <xsl:value-of select="regex-group(1)"/>
                    </xsl:matching-substring>                        
                </xsl:analyze-string>
            </xsl:element>

        </xsl:matching-substring>
        <xsl:non-matching-substring>
            <xsl:copy-of select="."/>
        </xsl:non-matching-substring>
     </xsl:analyze-string>         
</xsl:template>
    <xsl:template match="emphasis[@role='smallcaps'][not(preceding-sibling::node()[1][self::text() and matches(., 'BSK\s+(\p{L}{2,5})(\s+(I|II|III|IV|V|VI|VII))?\p{P}')])]" mode="copy-style">
     <xsl:element name="span">
            <xsl:attribute name="class">
                <xsl:value-of select="@role"/>
            </xsl:attribute>
            <xsl:apply-templates/>
        </xsl:element>       
     </xsl:template>
     <xsl:template match="emphasis[@role='smallcaps'][preceding-sibling::node()[1][self::text() and matches(., 'BSK\s+(\p{L}{2,5})(\s+(I|II|III|IV|V|VI|VII))?\p{P}')]]" mode="match">
    <xsl:element name="span">
        <xsl:attribute name="class">
            <xsl:value-of select="@role"/>
        </xsl:attribute>
        <xsl:apply-templates/>
      </xsl:element>       
     </xsl:template>
    <xsl:template mode="copy-style" match="text()[matches(., '^,?(\s+Vor)?\s+Art\.(\s+|\p{Zs})(\p{N}{1,4})\s+N(\s+|\p{Zs})(\p{N}{1,4})') and preceding-sibling::emphasis[@role='smallcaps'][1] and matches(preceding-sibling::emphasis[1]/preceding-sibling::text()[1], 'BSK\s+(\p{L}{2,5})(\s+(I|II|III|IV|V|VI|VII))?\p{P}')]">
     <xsl:variable name="pContent" select="string(.)"/>
     <xsl:analyze-string select="$pContent" regex="^,?(\s+Vor)?\s+Art\.(\s+|\p{{Zs}})(\p{{N}}{{1,4}})\s+N(\s+|\p{{Zs}})(\p{{N}}{{1,4}})">
        <xsl:matching-substring/>
        <xsl:non-matching-substring>
            <xsl:copy-of select="."/>
        </xsl:non-matching-substring>
      </xsl:analyze-string>
     </xsl:template>