0

Доброго времени суток! Пытаюсь выделить текст между двумя точками.

Смастерил бестолковый способ ......:

XML:

<con1:node>              
    <con2:node name="SomeName">
        <con2:path>'www.example.com.itsanexample.step1.step2.step3'</con2:path>
    </con2:node>
<con1:node>

XSLTv1:

<xsl:variable name="Variable1" select="//@name[normalize-space(.) = 'SomeName']/parent::*"/>

                <xsl:choose>
                    <xsl:when test="//@name[normalize-space(.) = 'SomeName']/parent::*">
                        <xsl:text>Your match:</xsl:text>
                        <xsl:value-of select="substring($Variable1, 35, 5)">
                        </xsl:value-of>
                    </xsl:when>
                    <xsl:otherwise> <xsl:text>0 matches!</xsl:text></xsl:otherwise>
</xsl:choose>

Output:
    Your Match: Step2

Проблема заключается в том, что www.example.com.itsanexample. всегда статична, a step1.step2.step3 всегда динамична. Например step122.step23.step3456 Неподскажите каким образом возможно выделить текст между 4й и 5й или 6й и 7й точкой, фокусируясь на characters а не на length?

1 ответ 1

0

Помогли на eng. если кому интересно;

Понадобился дополнительный параметр и головокружительный сабстринг.

<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

    <xsl:variable name="Variable1" select="//@name[normalize-space(.) = 'SomeName']/parent::*"/>
    <xsl:param name="string" select="$Variable1"/>

    <xsl:template match="/">

        <result>
            <xsl:value-of select="substring-before(substring-after(substring-after($string, 'www.example.com.itsanexample.'), '.'), '.')"/>
        </result>
    </xsl:template>

    </xsl:stylesheet>
1
  • Можно даже обойтись без <xsl:param name="string" select="$Variable1"/>, и поменять <xsl:value-of select="substring-before(substring-after(substring-after($string, 'www.example.com.itsanexample.'), '.'), '.')"/> на <xsl:value-of select="substring-before(substring-after(substring-after($Variable1, 'www.example.com.itsanexample.'), '.'), '.')"/> .
    – MypR
    31 авг 2017 в 7:57

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.