需要使用XSLT替换标记和引号

时间:2016-12-30 12:04:42

标签: json xml xslt dita

我想在引号内添加元素,但是如果我使用这个XSLT并且我在XSL中使用saxon PE 9.6.0.7和version = 2.0

那么它就不会出现

我的输入xml文件:

<text_top>
<p>Insulin is a medicine that is now an important part of your treatment plan. But you’re probably wondering, why now? Is my diabetes getting worse? Remember, with</p>
</text_top>
<text_bottom>
<p>So, to try and lower your blood glucose levels, your pancreas works overtime to get more insulin into your bloodstream, even though this insulin</p>
<p>As result, blood glucose levels increase, the pancreas eventually wears out, and the cells that produce the insulin in your pancreas are destroyed.</p>
</text_bottom>

XSL我用作:

    <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:template match="text_top">
    "top": "<xsl:sequence select="mf:break(normalize-space(string-join(node()/serialize(., $ser-params), '')))"/>",
</xsl:template>

<xsl:template match="text_bottom">
    "bottom": "<xsl:sequence select="mf:break(normalize-space(string-join(node()/serialize(., $ser-params), '')))"/>",
</xsl:template>

        <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="' +&#10; '"/>

        <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('&quot;', regex-group(2), '&quot;')"/>
                        <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:stylesheet>

我输出的json为:

"top": "<p>Insulin is a medicine that is now an" +
"important part of your treatment plan. But" +
"you’re probably wondering, why now? Is my" + 
"diabetes getting worse? Remember, with</p>",

"bottom": "<p>So, to try and lower your blood glucose" + 
"levels, your pancreas works overtime to" +
"get more insulin into your bloodstream, even" + 
"though this insulin</p><p>As result, blood glucose levels" +
"increase, the pancreas eventually wears out, and the cells" +
"that produce the insulin in your pancreas are destroyed.</p>"

但我希望json输出为:

"top": "<span>Insulin is a medicine that is now an" +
"important part of your treatment plan. But" +
"you’re probably wondering, why now? Is my" + 
"diabetes getting worse? Remember, with</span>",

"bottom": "<span>So, to try and lower your blood glucose" + 
"levels, your pancreas works overtime to" +
"get more insulin into your bloodstream, even" + 
"though this insulin</span>"

"<span>As result, blood glucose levels" +
"increase, the pancreas eventually wears out, and the cells" +
"that produce the insulin in your pancreas are destroyed.</span>"

请提前告知我,提前致谢。

1 个答案:

答案 0 :(得分:0)

使用unwanted xml versions coming in Json output using xslt中的方法,更改

CREATE TABLE #MyTempTable
(
    Name varchar(30)
)

CREATE PROC InsertData_To_TempTable(--Varying number of Names will go here)
AS
BEGIN
    INSERT INTO #MyTempTable(Name) 
    VALUES (--Varying list of values as input parameters from procedure)
END

EXEC InsertData_To_TempTable ('A'),('B') -- one time I may want to insert TWO values

EXEC InsertData_To_TempTable ('A'),('B'),('C') -- other time I may want to insert THREE values

 <xsl:template match="text_top">
    "top": <xsl:apply-templates/>,
</xsl:template>

<xsl:template match="text_bottom">
    "bottom": <xsl:apply-templates/>,
</xsl:template>

和必要的变量,如另一篇文章所示。