Hi all.
I'm very new to XSLT, was trying to make some very basic template and after a few hours of reading the docs and googling I'm here...
Hope for you this will be simple.
I have this XML:
What I want to get after filtering is like this:
What I tried so far:
But it does something unpredictable... or, better say it doesn't do anything
I would really appreciate if someone could just make a working example, instead of sending me to read the documentation... XSLT isn't really something I'm doing for living... that's the only time I need that thing and will not touch it ever again... hopefully. So, please, have mercy...
TIA.
EDIT:
OK, finally I got something like this:
And it seems to work... however it also looks very clumsy and convoluted to me... so, please, if you have a better idea about my task - don't hesitate to tell me...
I'm very new to XSLT, was trying to make some very basic template and after a few hours of reading the docs and googling I'm here...
Hope for you this will be simple.
I have this XML:
Code:
<data>
<foo name="someName"/>
<bar name="someOtherName"/>
<qwerty name="someName">
<nested-node/>
</querty>
</data>
What I want to get after filtering is like this:
Code:
<data>
<foo name="someName"/>
<qwerty name="someName">
<nested-node/>
</querty>
</data>
What I tried so far:
Code:
<xsl:stylesheet version="2.0" xmlns:xsl="---namespace URI---">
<xsl:template match="*|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="//*[@name='someName']">
</xsl:template>
</xsl:stylesheet>
I would really appreciate if someone could just make a working example, instead of sending me to read the documentation... XSLT isn't really something I'm doing for living... that's the only time I need that thing and will not touch it ever again... hopefully. So, please, have mercy...
TIA.
EDIT:
OK, finally I got something like this:
Code:
<xsl:stylesheet version="2.0"
xmlns:xsl="--- namespace URI ---">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="*">
<xsl:if test="@name='someName'">
<xsl:element name="{name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:value-of select="."/>
<xsl:for-each select="./*">
<xsl:call-template name="copyAll"/>
</xsl:for-each>
</xsl:element>
</xsl:if>
<xsl:apply-templates/>
</xsl:template>
<xsl:template name="copyAll">
<xsl:element name="{name()}">
<xsl:for-each select="@*">
<xsl:attribute name="{name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
<xsl:value-of select="."/>
<xsl:for-each select="./*">
<xsl:call-template name="copyAll"/>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
And it seems to work... however it also looks very clumsy and convoluted to me... so, please, if you have a better idea about my task - don't hesitate to tell me...
Last edited: