如何在XSLT1.0中实现拆分功能

如何在XSLT1.0中实现拆分功能,xslt,split,Xslt,Split,我有一个下面的场景。我有一个TEAM-MEMBERS节点,其名称的格式为last name,first name <TEAM-MEMBER><LONG-NAME>Last Name, First Name</LONG-NAME></TEAM-MEMBER> 姓、名 我想把它转换成 <CONTACT><FIRSTNAME>First Name</FIRSTNAME><LASTNAME>Last Na

我有一个下面的场景。我有一个TEAM-MEMBERS节点,其名称的格式为last name,first name

<TEAM-MEMBER><LONG-NAME>Last Name, First Name</LONG-NAME></TEAM-MEMBER>
姓、名
我想把它转换成

<CONTACT><FIRSTNAME>First Name</FIRSTNAME><LASTNAME>Last Name</LASTNAME></CONTACT>
名字姓氏
基本上,我想将
节点的值除以

如何使用XSLT1.0实现这一点

此XSLT将由BizTalk Server使用,因此我只寻找一些XSLT 1.0解决方案

谢谢


Karthik

您需要一个递归命名模板。幸运的是,它已经被编写好了:查找
str:tokenize
at.

使用
substring-after()
substring-before()
来绕过拆分这里有一个完整的XSLT 1.0解决方案,它使用一个通用的“拆分”模板将字符串拆分为多个子字符串,提供了一个分隔符来指定子字符串之间的边界:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:ext="http://exslt.org/common" exclude-result-prefixes="ext">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="TEAM-MEMBER">
  <xsl:variable name="vrtfSplitWords">
   <xsl:call-template name="split">
    <xsl:with-param name="pText" select="."/>
   </xsl:call-template>
  </xsl:variable>

  <xsl:variable name="vSplitWords"
  select="ext:node-set($vrtfSplitWords)/*"/>

  <CONTACT>
   <FIRSTNAME><xsl:value-of select="$vSplitWords[2]"/></FIRSTNAME>
   <LASTNAME><xsl:value-of select="$vSplitWords[1]"/></LASTNAME>
  </CONTACT>
 </xsl:template>

 <xsl:template name="split">
  <xsl:param name="pText" select="."/>
  <xsl:param name="pDelim" select="', '"/>
  <xsl:param name="pElemName" select="'word'"/>

  <xsl:if test="string-length($pText)">
   <xsl:element name="{$pElemName}">
    <xsl:value-of select=
     "substring-before(concat($pText,$pDelim),
                       $pDelim
                      )
     "/>
   </xsl:element>

   <xsl:call-template name="split">
    <xsl:with-param name="pText" select=
    "substring-after($pText,$pDelim)"/>
    <xsl:with-param name="pDelim" select="$pDelim"/>
    <xsl:with-param name="pElemName" select="$pElemName"/>
   </xsl:call-template>
  </xsl:if>
 </xsl:template>
</xsl:stylesheet>
应用于此XML文档时(变得非常复杂):

名字,(小),姓
生成所需的正确结果

<CONTACT>
   <FIRSTNAME>First Name</FIRSTNAME>
   <LASTNAME>Last Name</LASTNAME>
</CONTACT>
<FIRSTNAME>First Name</FIRSTNAME>
<MIDNAME>Jr.</MIDNAME>
<LASTNAME>Last Name</LASTNAME>
名字
年少者。
姓
注意事项

<CONTACT>
   <FIRSTNAME>First Name</FIRSTNAME>
   <LASTNAME>Last Name</LASTNAME>
</CONTACT>
<FIRSTNAME>First Name</FIRSTNAME>
<MIDNAME>Jr.</MIDNAME>
<LASTNAME>Last Name</LASTNAME>

str拆分为单词的模板接受多个分隔符。因此,在这个转换中使用的分隔符是:
,“
”(“
”)“

如果您的代码正常工作,请发布您的代码(首选)或关闭“不再相关”的问题。好问题,+1。请参阅我的答案,了解两个XSLT 1.0解决方案,每个解决方案都提供了一个通用模板,可以在给定一组分隔符的情况下将字符串拆分为子字符串(无论有多少)谢谢你的详细回答。
<FIRSTNAME>First Name</FIRSTNAME>
<MIDNAME>Jr.</MIDNAME>
<LASTNAME>Last Name</LASTNAME>