XSLT 1.0 - переместить определенные элементы в нового родителя

Независимо от решений, предоставляемых другими, полностью основаны на доступном методе find () или любых доступных методах.

Каков основной базовый алгоритм для поиска всех вхождений подстроки в string?

def find_all(string,substring):
    """
    Function: Returning all the index of substring in a string
    Arguments: String and the search string
    Return:Returning a list
    """
    length = len(substring)
    c=0
    indexes = []
    while c < len(string):
        if string[c:c+length] == substring:
            indexes.append(c)
        c=c+1
    return indexes

Вы также можете наследовать класс str новому классу и можете использовать эту функцию ниже.

class newstr(str):
def find_all(string,substring):
    """
    Function: Returning all the index of substring in a string
    Arguments: String and the search string
    Return:Returning a list
    """
    length = len(substring)
    c=0
    indexes = []
    while c < len(string):
        if string[c:c+length] == substring:
            indexes.append(c)
        c=c+1
    return indexes

Вызов метод

newstr.find_all («Вы находите, что этот ответ полезен, а затем повышайте это!», «это»)

0
задан arjun ajjarapu 17 January 2019 в 04:53
поделиться

1 ответ

Попробуйте это так:

XSLT 1.0

<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:strip-space elements="*"/>

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

<xsl:template match="/root">
    <xsl:copy>
        <newparent>
            <xsl:apply-templates select="a|b|c"/>
        </newparent>
        <xsl:apply-templates select="*[not(self::a or self::b or self::c)]"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="*[not(@* or node())]"/>

</xsl:stylesheet>
0
ответ дан michael.hor257k 17 January 2019 в 04:53
поделиться
Другие вопросы по тегам:

Похожие вопросы: