| | |
How to add an enclosing node to text including nodes?
Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Sep 2009
Posts: 2
Reputation:
Solved Threads: 0
Hi,
I want to process the following xml:
...
<a>
HHHHeader 1 : xxx <it> yyy </it> zzz
HHHHeader 2 : aaa bbb <it> ccc </it>
</a>
...
And I want to get via a xslt the following xml
...
<a>
<Header hd="1">
xxx <it> yyy </it> zzz
</Header>
<Header hd="2">
aaa bbb <it> ccc </it>
</Header>
</a>
...
Using code like this
<xsl:template match="a">
<xsl:variable name="elValue" select="."/>
<xsl:analyze-string select="$elValue"
regex="HHHHeader ([0-9]*)\s:([\s\S]*)">
<xsl:matching-substring>
<xsl:element name="Header">
<xsl:attribute name="hd" select="regex-group(1)"/>
<xsl:value-of select="regex-group(2)"/>
</xsl:element>
</xsl:matching-substring>
<xsl:non-matching-substring>
<aInError>
<xsl:value-of select="$elValue"/>
</aInError>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
I know how to create the following xml
<a>
<Header hd="1">
xxx yyy zzz
</Header>
<Header hd="2">
aaa bbb ccc
</Header>
</a>
but then the <it> nodes are lost. I have no clue how I could proceed to keep these. Anyone can help ?
Thanx
I want to process the following xml:
...
<a>
HHHHeader 1 : xxx <it> yyy </it> zzz
HHHHeader 2 : aaa bbb <it> ccc </it>
</a>
...
And I want to get via a xslt the following xml
...
<a>
<Header hd="1">
xxx <it> yyy </it> zzz
</Header>
<Header hd="2">
aaa bbb <it> ccc </it>
</Header>
</a>
...
Using code like this
<xsl:template match="a">
<xsl:variable name="elValue" select="."/>
<xsl:analyze-string select="$elValue"
regex="HHHHeader ([0-9]*)\s:([\s\S]*)">
<xsl:matching-substring>
<xsl:element name="Header">
<xsl:attribute name="hd" select="regex-group(1)"/>
<xsl:value-of select="regex-group(2)"/>
</xsl:element>
</xsl:matching-substring>
<xsl:non-matching-substring>
<aInError>
<xsl:value-of select="$elValue"/>
</aInError>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:template>
I know how to create the following xml
<a>
<Header hd="1">
xxx yyy zzz
</Header>
<Header hd="2">
aaa bbb ccc
</Header>
</a>
but then the <it> nodes are lost. I have no clue how I could proceed to keep these. Anyone can help ?
Thanx
![]() |
Similar Threads
- treeview and node class (C#)
- Difference between adding a node and creating a list of nodes (Java)
- Adding Or Changing the Text Of Child Nodes in TreeView - Visual c++ 2008 (C++)
- LNK2001 and LNK2019 problem! (C++)
- Treeview Child Nodes (VB.NET)
- Help, Add and Delete many useres from text file (Shell Scripting)
- Inserting Nodes between Nodes (XML, XSLT and XPATH)
- add node to xmlfile (C#)
- Problem with Treeview control...... (ASP.NET)
Other Threads in the XML, XSLT and XPATH Forum
- Previous Thread: [XSLT] Group tags to prioritize the xml file
- Next Thread: include, call-template
| Thread Tools | Search this Thread |
Tag cloud for XML, XSLT and XPATH
api blogger blogging code delete development dynamiccreationofnvariablesinxslt error firstthreecharacterofastringrequired flipbook gdata google html include java link linspire linux microsoft news node openoffice overwrite precedence programming rss standards swf template transform variable w3c web xml xmlnotloading xmlonserver xsl xslt





