Reputation: 3224
I want to transfer XML file to other XML with XSLT. I want to do transformation because XML file isn't pure tree-structured document.
Here's my file before:
<uglyStartTag></uglyStartTag>
<name>content</name>
<uglyEndTag></uglyEndTag>
or
<uglyStartTag/>
<name>content</name>
<uglyEndTag/>
Here's my file after:
<beautyTag>
<name>content</name>
</beautyTag>
How can I do it? I'm not familiarized with XSLT so I will be thankful for any advice.
Upvotes: 0
Views: 145
Reputation: 243459
This transformation:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match=
"node()[preceding-sibling::uglyStartTag
and
following-sibling::uglyEndTag
][1]">
<beautyTag>
<xsl:copy-of select=
"../node()[preceding-sibling::uglyStartTag
and
following-sibling::uglyEndTag
]
"/>
</beautyTag>
</xsl:template>
</xsl:stylesheet>
when applied on this XML document (provided by the OP in a comment):
<t>
<uglyStartTag />
<name>dgsdgsdgsdg</name>
<uglyEndTag />
</t>
produces the wanted, correct result:
<beautyTag>
<name>dgsdgsdgsdg</name>
</beautyTag>
Upvotes: 1