Xml 字符串拆分需要XSLT

Xml 字符串拆分需要XSLT,xml,xslt,xpath,Xml,Xslt,Xpath,我有XML格式的数据 1 $ Mahesh $ SE $ ITO;2 $ umesh $ TE $ HBS;3 $ somesh$ SE $ ITO; 我必须根据“;”分割这个字符串然后用“$”拆分每个字符串 我可以做一个级别,但被下一个级别的spplit搞得焦头烂额 使用此模板: <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3

我有XML格式的数据

1 $ Mahesh $ SE $ ITO;2 $ umesh $ TE $ HBS;3 $ somesh$ SE $ ITO;
我必须根据“;”分割这个字符串然后用“$”拆分每个字符串

我可以做一个级别,但被下一个级别的spplit搞得焦头烂额



使用此模板:

<?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" indent="yes"/>

    <xsl:template match="/">
        <xsl:variable name="s">1 $ Mahesh $ SE $ ITO;2 $ umesh $ TE $ HBS;3 $ somesh$ SE $ ITO;</xsl:variable>

        <result>
            <xsl:call-template name="split">
                <xsl:with-param name="pText" select="$s"/>
            </xsl:call-template>
        </result>
    </xsl:template>


    <xsl:template name="split">
        <xsl:param name="pText"/>

        <xsl:if test="string-length($pText)">

            <group value="{substring-before($pText, ';')}">
                <xsl:call-template name="split2">
                    <xsl:with-param name="pText" select="substring-before($pText, ';')"/>
                </xsl:call-template>
            </group>

            <xsl:call-template name="split">
                <xsl:with-param name="pText" select="substring-after($pText, ';')"/>
            </xsl:call-template>
        </xsl:if>
    </xsl:template>

    <xsl:template name="split2">
        <xsl:param name="pText"/>

        <xsl:if test="string-length($pText)">
            <item>
                <xsl:choose>
                    <xsl:when test="contains($pText, '$')">
                        <xsl:value-of select="normalize-space(substring-before($pText, '$'))"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="normalize-space($pText)"/>
                    </xsl:otherwise>
                </xsl:choose>
            </item>

            <xsl:call-template name="split2">
                <xsl:with-param name="pText" select="substring-after($pText, '$')"/>
            </xsl:call-template>
        </xsl:if>

    </xsl:template>

</xsl:stylesheet>

1$Mahesh$SE$ITO;2$umesh$TE$HBS;3$somesh$SE$ITO;

输出:

<?xml version="1.0" encoding="utf-8"?>
<result>
  <group value="1 $ Mahesh $ SE $ ITO">
    <item>1</item>
    <item>Mahesh</item>
    <item>SE</item>
    <item>ITO</item>
  </group>
  <group value="2 $ umesh $ TE $ HBS">
    <item>2</item>
    <item>umesh</item>
    <item>TE</item>
    <item>HBS</item>
  </group>
  <group value="3 $ somesh$ SE $ ITO">
    <item>3</item>
    <item>somesh</item>
    <item>SE</item>
    <item>ITO</item>
  </group>
</result>

1.
马赫什
东南方
伊藤
2.
乌梅什
TE
哈佛商学院
3.
萨默什
东南方
伊藤

可能,您能告诉我如何增加概率吗?我将所有问题都标记为已回答,不确定您的确切期望是什么
<?xml version="1.0" encoding="utf-8"?>
<result>
  <group value="1 $ Mahesh $ SE $ ITO">
    <item>1</item>
    <item>Mahesh</item>
    <item>SE</item>
    <item>ITO</item>
  </group>
  <group value="2 $ umesh $ TE $ HBS">
    <item>2</item>
    <item>umesh</item>
    <item>TE</item>
    <item>HBS</item>
  </group>
  <group value="3 $ somesh$ SE $ ITO">
    <item>3</item>
    <item>somesh</item>
    <item>SE</item>
    <item>ITO</item>
  </group>
</result>