A few days ago, there is a problem on the forum (see: http://community.csdn.net/Expert/topic/3237/3237160.xml? Temp =. 6712152)
To solve this problem, we mainly apply two functions in XPath: substring-before; substring-after
An example is as follows:
Test. xml:
<? XML version = "1.0" encoding = "UTF-8"?>
<Data_info cc_id = '2013'/>
-----------------------------------------------------------------------
Test. XSL:
<? XML version = "1.0" encoding = "UTF-8"?>
<XSL: stylesheet version = "1.0" xmlns: XSL = "http://www.w3.org/1999/XSL/Transform">
<XSL: Output indent = "yes" method = "XML" encoding = "UTF-8"/>
<XSL: template match = "/data_info">
<XSL: element name = "{name ()}">
<XSL: Call-Template Name = "splitstr">
<XSL: With-Param name = "str" select = "@ cc_id"/>
<XSL: With-Param name = "ctrlname" select = "'CC _ id'"/>
</XSL: Call-template>
</XSL: Element>
</XSL: Template>
<XSL: Template Name = "splitstr">
<XSL: Param name = "str"/>
<XSL: Param name = "ctrlname"/>
<XSL: element name = "input">
<XSL: attribute name = "name"> <XSL: value-of select = "$ ctrlname"/> </XSL: attribute>
<XSL: attribute name = "value">
<XSL: Choose>
<XSL: When test = "contains ($ STR, ',')"> <XSL: value-of select = "substring-before ($ STR ,',') "/> </XSL: When>
<XSL: otherwise> <XSL: value-of select = "$ Str"/> </XSL: otherwise>
</XSL: Choose>
</XSL: attribute>
</XSL: Element>
<XSL: If test = "contains ($ STR, ',')">
<XSL: Call-Template Name = "splitstr">
<XSL: With-Param name = "str" select = "substring-after ($ STR, ',')"/>
<XSL: With-Param name = "ctrlname" select = "$ ctrlname"/>
</XSL: Call-template>
</XSL: If>
</XSL: Template>
</XSL: stylesheet>
--------------------------------------------------------------------------------
Conversion Result:
<? XML version = "1.0" encoding = "UTF-8"?>
<Data_info>
<Input name = "cc_id" value = "195"/>
<Input name = "cc_id" value = "196"/>
<Input name = "cc_id" value = "197"/>
<Input name = "cc_id" value = "198"/>
</Data_info>