を使用して、特定の出現に含める必要が要素タグは、私はXSLTを使用して、引用符内のタグを含めるXSLT
私の入力XMLは次のとおりです。
<xsl:stylesheet version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:json="http://json.org/" xmlns:mf="http://example.com/mf"
exclude-result-prefixes="#all">
<xsl:param name="length" as="xs:integer" select="80"/>
<xsl:param name="pattern" as="xs:string" select="concat('((.{1,', $length, '})(|$))')"/>
<xsl:param name="sep" as="xs:string" select="' + '"/>
<xsl:function name="mf:break" as="xs:string">
<xsl:param name="input" as="xs:string"/>
<xsl:variable name="result">
<xsl:analyze-string select="$input" regex="{$pattern}">
<xsl:matching-substring>
<xsl:value-of select="concat('"', regex-group(2), '"')"/>
<xsl:if test="position() ne last()">
<xsl:value-of select="$sep"/>
</xsl:if>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:sequence select="$result"/>
</xsl:function>
<xsl:param name="ser-params" as="element()">
<output:serialization-parameters xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization">
<output:method value="xml"/>
<output:version value="1.0"/>
<output:indent value="yes"/>
<output:omit-xml-declaration value="yes"/>
</output:serialization-parameters>
</xsl:param>
<xsl:template match="top">
"top": <xsl:apply-templates/>,
</xsl:template>
<xsl:template match="bottom">
"bottom": <xsl:apply-templates/>,
</xsl:template>
<xsl:template match="p">
<span><xsl:sequence select="mf:break(normalize-space(string-join(text()/serialize(., $ser-params), '')))"/></span>
</xsl:template>
</xsl:stylesheet>
:私はとして使用
<text>
<top>
<p>Glucose builds up in your blood and your cells become starved for energy and can’t function properly.</p>
</top>
<bottom>
<p>And, for some people, this may be all that is needed to successfully maintain target blood glucose levels.</p>
<p>It doesn’t come in a pill form because it would get destroyed in the stomach during digestion.</p>
</bottom>
</text>
XSL
私はのような出力を得た:
"top": <span>"Glucose builds up in your blood and your cells become" +
"starved for energy and can’t function properly."</span>,
"bottom": <span>"And, for some people, this may be all that is needed" +
"to successfully maintain target blood glucose levels."</span>
<span>"It doesn’t come in a pill form because it would get destroyed in" +
"the stomach during digestion."</span>,
しかし、私はのような出力が必要になります。私は、タグは、引用符の内側に来たい
"top": "<span>Glucose builds up in your blood and your cells become" +
"starved for energy and can’t function properly.</span>",
"bottom": "<span>And, for some people, this may be all that is needed" +
"to successfully maintain target blood glucose levels.</span>"
"<span>It doesn’t come in a pill form because it would get destroyed in" +
"the stomach during digestion.</span>",
、この上で私を助けてください。事前に感謝
その。どうもありがとうございます。 – User501