enthuguy
asked on
How to remove nodes from xml based on the value of a tag
Hi,
Using xml and xsl, I would like to parse input xml for a particular node and tag. If the tag value starts with “z” then I would like to delete that node itself. (or create new file without this node)
Have attached a sample xml file for reference. From this I would expect the last node should be removed.
if ListOfFields/Field/ListOfF ieldTransl ations/Fie ldTranslat ion/Displa yName starts with z then this delete node
<ns1:Field>
<ns1:Name>name4</ns1:Name>
<ns1:ListOfFieldTranslatio ns>
<ns1:FieldTranslation>
<ns1:DisplayName>zIndividu al</ns1:Di splayName>
<ns1:ValidationErrorMsg>In dividual.< /ns1:Valid ationError Msg>
</ns1:FieldTranslation>
</ns1:ListOfFieldTranslati ons>
</ns1:Field>
Also could you please suggest XSLT editor for me learn or play arount? or a best XML/XLST editor for a reasonable price
Thanks in advance.
sample-xml.xml
Using xml and xsl, I would like to parse input xml for a particular node and tag. If the tag value starts with “z” then I would like to delete that node itself. (or create new file without this node)
Have attached a sample xml file for reference. From this I would expect the last node should be removed.
if ListOfFields/Field/ListOfF
<ns1:Field>
<ns1:Name>name4</ns1:Name>
<ns1:ListOfFieldTranslatio
<ns1:FieldTranslation>
<ns1:DisplayName>zIndividu
<ns1:ValidationErrorMsg>In
</ns1:FieldTranslation>
</ns1:ListOfFieldTranslati
</ns1:Field>
Also could you please suggest XSLT editor for me learn or play arount? or a best XML/XLST editor for a reasonable price
Thanks in advance.
sample-xml.xml
You have to create a template that matches the value-of a node starting by "z" and do nothing when it matches
ASKER
yep, thats the idea. I managed to get on how to check the element...contains text()?
But need help on how to search the string
Below is the one got it from google search. on how to check is element emplty or not.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="giro[not(nombreGiro /text())]" />
</xsl:stylesheet>
But need help on how to search the string
Below is the one got it from google search. on how to check is element emplty or not.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes"
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="giro[not(nombreGiro
</xsl:stylesheet>
ASKER
Can any one give me the sample xslt pls
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="urn:/crmondemand/xml/fldmgmt/data">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ns1:DisplayName[starts-with(normalize-space(), 'z')]"/>
</xsl:stylesheet>
By far the best editor for XML and testing XSLT is Oxygen
www.oxygenxml.com
it is fairly priced, and you can use the development edition and test it for a month for free
You will be convinced after that month
www.oxygenxml.com
it is fairly priced, and you can use the development edition and test it for a month for free
You will be convinced after that month
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
with a slight change
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="urn:/crmondeman d/xml/fiel dmanagemen t/data"
exclude-result-prefixes="n s1">
<xsl:param name="testParam"/>
<xsl:output method="text" indent="no" />
<xsl:template match="@*|node()" >
<xsl:apply-templates select="@*|node()" />
</xsl:template>
<xsl:template match="ns1:ListOfFields[ not (node()) ]">
<xsl:text>false</xsl:text>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1="urn:/crmondeman
exclude-result-prefixes="n
<xsl:param name="testParam"/>
<xsl:output method="text" indent="no" />
<xsl:template match="@*|node()" >
<xsl:apply-templates select="@*|node()" />
</xsl:template>
<xsl:template match="ns1:ListOfFields[ not (node()) ]">
<xsl:text>false</xsl:text>
</xsl:template>
</xsl:stylesheet>