String 字符串替换和连接

String 字符串替换和连接,string,xslt,replace,concatenation,xslt-1.0,String,Xslt,Replace,Concatenation,Xslt 1.0,我有这个结构 <ROWS> <ROW> <TEXT> This is a @good@ @day@ </TEXT> <good>great</good> <day>month</day> </ROW> <ROW> <TEXT> This is a @good@ @day@ </TEXT> <goo

我有这个结构

<ROWS>
  <ROW>
    <TEXT> This is a @good@ @day@ </TEXT>
    <good>great</good>
    <day>month</day>
  </ROW>
  <ROW>
    <TEXT> This is a @good@ @day@ </TEXT>
    <good>Fun</good>
    <day>morning</day>
  </ROW>
</ROWS>

今天是“好日子”
伟大的
月
今天是“好日子”
乐趣
早晨
我怎么把它改成

<statement> This is a great month, this is a Fun morning </statement>
这是一个伟大的月份,这是一个有趣的早晨
仅使用XSLT1.0


原始XML可以更改标记名。但不是结构!有什么想法吗?

看看;查找有关字符串函数的部分。研究contains、substring before和substring after函数。你的问题的解决方案应该变得清晰;如果没有,你至少应该能够在你的问题上取得足够的进展,提出一个看起来不可能被解释为“请为我做家庭作业”的问题;查找有关字符串函数的部分。研究contains、substring before和substring after函数。你的问题的解决方案应该变得清晰;如果没有,你至少应该能够在你的问题上取得足够的进展,提出一个看起来不可能被解释为“请为我做家庭作业”的问题;查找有关字符串函数的部分。研究contains、substring before和substring after函数。你的问题的解决方案应该变得清晰;如果没有,你至少应该能够在你的问题上取得足够的进展,提出一个看起来不可能被解释为“请为我做家庭作业”的问题;查找有关字符串函数的部分。研究contains、substring before和substring after函数。你的问题的解决方案应该变得清晰;如果没有,你至少应该能够在你的问题上取得足够的进展,提出一个看起来不可能被解释为“请为我做家庭作业”的问题。

这似乎有点类似于从模板创建表单信函。假设该示例不是字面意思,您可以尝试以下操作:

<?xml version="1.0" encoding="UTF-8"?>
<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:template match="/">
    <statements>
        <xsl:for-each select="ROWS/ROW/TEXT">
            <statement>
                <xsl:call-template name="merge">
                    <xsl:with-param name="string" select="."/>
                </xsl:call-template>
            </statement>
        </xsl:for-each>
    </statements>
</xsl:template>

<xsl:template name="merge">
    <xsl:param name="string"/>
    <xsl:param name="sep" select="'@'"/>
    <xsl:choose>
        <xsl:when test="contains($string, $sep) and contains(substring-after($string, $sep), $sep)">
            <xsl:value-of select="substring-before($string, $sep)" />
            <xsl:variable name="placeholder" select="substring-before(substring-after($string, $sep), $sep)" />
            <xsl:value-of select="../*[name() = $placeholder]" />
            <!-- recursive call -->
            <xsl:call-template name="merge">
                <xsl:with-param name="string" select="substring-after(substring-after($string, $sep), $sep)" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$string" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

</xsl:stylesheet>

如果输入:

<ROWS>
  <ROW>
    <TEXT>The quick brown @animal@ jumps over the @property@ dog.</TEXT>
    <animal>fox</animal>
    <property>lazy</property>
  </ROW>
  <ROW>
    <TEXT>A journey of a @number@ miles @action@ with a single @act@.</TEXT>
    <number>thousand</number>
    <action>begins</action>
    <act>step</act>
  </ROW>
</ROWS>

那个敏捷的棕色“动物”跳过了“财产”狗。
狐狸
懒惰的
单程旅行一个“数字”英里数“行动”@act@.
千
开始
步
结果将是:

<?xml version="1.0" encoding="UTF-8"?>
<statements>
   <statement>The quick brown fox jumps over the lazy dog.</statement>
   <statement>A journey of a thousand miles begins with a single step.</statement>
</statements>

敏捷的棕色狐狸跳过了懒狗。
千里之行始于足下。

这似乎有点类似于从模板创建表单信函。假设该示例不是字面意思,您可以尝试以下操作:

<?xml version="1.0" encoding="UTF-8"?>
<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:template match="/">
    <statements>
        <xsl:for-each select="ROWS/ROW/TEXT">
            <statement>
                <xsl:call-template name="merge">
                    <xsl:with-param name="string" select="."/>
                </xsl:call-template>
            </statement>
        </xsl:for-each>
    </statements>
</xsl:template>

<xsl:template name="merge">
    <xsl:param name="string"/>
    <xsl:param name="sep" select="'@'"/>
    <xsl:choose>
        <xsl:when test="contains($string, $sep) and contains(substring-after($string, $sep), $sep)">
            <xsl:value-of select="substring-before($string, $sep)" />
            <xsl:variable name="placeholder" select="substring-before(substring-after($string, $sep), $sep)" />
            <xsl:value-of select="../*[name() = $placeholder]" />
            <!-- recursive call -->
            <xsl:call-template name="merge">
                <xsl:with-param name="string" select="substring-after(substring-after($string, $sep), $sep)" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$string" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

</xsl:stylesheet>

如果输入:

<ROWS>
  <ROW>
    <TEXT>The quick brown @animal@ jumps over the @property@ dog.</TEXT>
    <animal>fox</animal>
    <property>lazy</property>
  </ROW>
  <ROW>
    <TEXT>A journey of a @number@ miles @action@ with a single @act@.</TEXT>
    <number>thousand</number>
    <action>begins</action>
    <act>step</act>
  </ROW>
</ROWS>

那个敏捷的棕色“动物”跳过了“财产”狗。
狐狸
懒惰的
单程旅行一个“数字”英里数“行动”@act@.
千
开始
步
结果将是:

<?xml version="1.0" encoding="UTF-8"?>
<statements>
   <statement>The quick brown fox jumps over the lazy dog.</statement>
   <statement>A journey of a thousand miles begins with a single step.</statement>
</statements>

敏捷的棕色狐狸跳过了懒狗。
千里之行始于足下。

这似乎有点类似于从模板创建表单信函。假设该示例不是字面意思,您可以尝试以下操作:

<?xml version="1.0" encoding="UTF-8"?>
<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:template match="/">
    <statements>
        <xsl:for-each select="ROWS/ROW/TEXT">
            <statement>
                <xsl:call-template name="merge">
                    <xsl:with-param name="string" select="."/>
                </xsl:call-template>
            </statement>
        </xsl:for-each>
    </statements>
</xsl:template>

<xsl:template name="merge">
    <xsl:param name="string"/>
    <xsl:param name="sep" select="'@'"/>
    <xsl:choose>
        <xsl:when test="contains($string, $sep) and contains(substring-after($string, $sep), $sep)">
            <xsl:value-of select="substring-before($string, $sep)" />
            <xsl:variable name="placeholder" select="substring-before(substring-after($string, $sep), $sep)" />
            <xsl:value-of select="../*[name() = $placeholder]" />
            <!-- recursive call -->
            <xsl:call-template name="merge">
                <xsl:with-param name="string" select="substring-after(substring-after($string, $sep), $sep)" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$string" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

</xsl:stylesheet>

如果输入:

<ROWS>
  <ROW>
    <TEXT>The quick brown @animal@ jumps over the @property@ dog.</TEXT>
    <animal>fox</animal>
    <property>lazy</property>
  </ROW>
  <ROW>
    <TEXT>A journey of a @number@ miles @action@ with a single @act@.</TEXT>
    <number>thousand</number>
    <action>begins</action>
    <act>step</act>
  </ROW>
</ROWS>

那个敏捷的棕色“动物”跳过了“财产”狗。
狐狸
懒惰的
单程旅行一个“数字”英里数“行动”@act@.
千
开始
步
结果将是:

<?xml version="1.0" encoding="UTF-8"?>
<statements>
   <statement>The quick brown fox jumps over the lazy dog.</statement>
   <statement>A journey of a thousand miles begins with a single step.</statement>
</statements>

敏捷的棕色狐狸跳过了懒狗。
千里之行始于足下。

这似乎有点类似于从模板创建表单信函。假设该示例不是字面意思,您可以尝试以下操作:

<?xml version="1.0" encoding="UTF-8"?>
<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:template match="/">
    <statements>
        <xsl:for-each select="ROWS/ROW/TEXT">
            <statement>
                <xsl:call-template name="merge">
                    <xsl:with-param name="string" select="."/>
                </xsl:call-template>
            </statement>
        </xsl:for-each>
    </statements>
</xsl:template>

<xsl:template name="merge">
    <xsl:param name="string"/>
    <xsl:param name="sep" select="'@'"/>
    <xsl:choose>
        <xsl:when test="contains($string, $sep) and contains(substring-after($string, $sep), $sep)">
            <xsl:value-of select="substring-before($string, $sep)" />
            <xsl:variable name="placeholder" select="substring-before(substring-after($string, $sep), $sep)" />
            <xsl:value-of select="../*[name() = $placeholder]" />
            <!-- recursive call -->
            <xsl:call-template name="merge">
                <xsl:with-param name="string" select="substring-after(substring-after($string, $sep), $sep)" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$string" />
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

</xsl:stylesheet>

如果输入:

<ROWS>
  <ROW>
    <TEXT>The quick brown @animal@ jumps over the @property@ dog.</TEXT>
    <animal>fox</animal>
    <property>lazy</property>
  </ROW>
  <ROW>
    <TEXT>A journey of a @number@ miles @action@ with a single @act@.</TEXT>
    <number>thousand</number>
    <action>begins</action>
    <act>step</act>
  </ROW>
</ROWS>

那个敏捷的棕色“动物”跳过了“财产”狗。
狐狸
懒惰的
单程旅行一个“数字”英里数“行动”@act@.
千
开始
步
结果将是:

<?xml version="1.0" encoding="UTF-8"?>
<statements>
   <statement>The quick brown fox jumps over the lazy dog.</statement>
   <statement>A journey of a thousand miles begins with a single step.</statement>
</statements>

敏捷的棕色狐狸跳过了懒狗。
千里之行始于足下。

发布XML时,请正确缩进。第二,你应该努力解决这个问题。请编辑您的帖子并展示您迄今为止所做的尝试。有关更多详细信息,请阅读和。哪些名称可以更改,哪些不能更改?如何知道将第二个名称开头的T更改为小写的T?是否应始终将每行的第一个字母改为小写字母?发布XML时,请正确缩进。第二,你应该努力解决这个问题。请编辑您的帖子并展示您迄今为止所做的尝试。有关更多详细信息,请阅读和。哪些名称可以更改,哪些不能更改?如何知道将第二个名称开头的T更改为小写的T?是否应始终将每行的第一个字母改为小写字母?发布XML时,请正确缩进。其次