(I accidentally didn't post to the mailing-list before, but since this might be useful to other people, I'm sending the entire thread now.  Hope you don't mind)

Hey, maybe this doesn't apply to your application (since your elements are only one level deep), but you might consider changing the template to match like this:

<xsl:template match="@*|*[//text()|//@*]">

so that it will apply to nodes that also have other nodes with text and/or attribute nodes as descendants.

[EMAIL PROTECTED] wrote:
Hi Peter
I tested what u send and it works - I did a slight modification on it - so
that it does not delete any node like <x a="b"/> - which has an attribute
but no value.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version
="1.0">

<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|*[text()|*|@*]">
<xsl:copy>
<xsl:apply-templates select="@*|*|text()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

thanks for the help
Anamitra



Peter Davis
<[EMAIL PROTECTED] To: [EMAIL PROTECTED]
nk.com> cc:
Subject: Re: stripping xml elements without values
11/16/2001
06:06 PM






Maybe you can do something like this (I tested it with X alan D11, so I'm
pretty sure it will work for you). This is based off of the identity
template example given in the XSLT spec:

<xsl:stylesheet ...>
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|*[text()|*]">
<xsl:copy>
<xsl:apply-templates select="@*|*|text()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

The match on the template only matches attributes and nodes that have
either a text node child or a child that has a text node. When the
template is applied, it then applies templates on each of the
attributes, child nodes, and text nodes within that template.

The xsl:strip-space makes sure that the template does not match elements
that only have whitespace text-nodes inside. This may or may not be
what you want. The <xsl:output indent="yes"> makes it so even though we
put the xsl:strip-space, it d oesn't squish all the elements onto one
line in the output.

Hope that helps!

[EMAIL PROTECTED] wrote:

Hi
Is it possibe to write a generic xsl script which will allow me to strip
all elements with null/values like
in xml:
<PSCAMA class="R">
<LANGUAGE_CD>ENG</LANGUAGE_CD>
<AUDIT_ACTN></AUDIT_ACTN>
<BASE_LANGUAGE_CD>ENG</BASE_LANGUAGE_CD>
<MSG_SEQ_FLG></MSG_SEQ_FLG>
<PROCESS_INSTANCE>0</PROCESS_INSTANCE>
<PUBLISH_RULE_ID></PUBLISH_RULE_ID>
<MSGNODENAME></MSGNODENAME>
</PSCAMA>

out xml:
<PSCAMA class="R">
<LANGUAGE_CD>ENG</LANGUAGE_CD>
<BASE_LANGUAGE_CD>ENG</BASE_LANGUAGE_CD>
<PROCESS_INSTANCE>0</PROCESS_INSTANCE>
</PSCAMA>

This is just simple xml file - what I need is a generic way to strip off
all empty tags from any input xml. I was trying to use xsl:strip-space
element - but its giving star nge results. Is there anything currently in
xsl that I can use.??

thanks
Anamitra




--
Furthermore, I believe bacon prevents hair loss.

Peter Davis
Developer, Speaklink Inc.
[EMAIL PROTECTED]










-- 
Furthermore, I believe bacon prevents hair loss.

Peter Davis
Developer, Speaklink Inc.
[EMAIL PROTECTED]

Reply via email to