xsl-list
[Top] [All Lists]

Re: [xsl] Get children and text, excluding a child

2015-06-12 17:44:10
Just override the identity transformation, for example like this:

<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()|@*">
    <xsl:copy>
      <xsl:apply-templates select="node()|@*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="span/number"/>
</xsl:stylesheet>

When this transformation is applied on the provided source XML document:


<root>
  <span><number>9.3</number> <code>protected</code> members</span>
  <span><number>9.4</number> miscellaneous members.</span>
< /root>

The wanted, correct result is produced:

<root>
   <span>
      <code>protected</code> members</span>
   <span> miscellaneous members.</span>
</root>


On Fri, Jun 12, 2015 at 1:44 PM, Rick Quatro rick(_at_)rickquatro(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:
Hello,

Here is my input xml:

<?xml version="1.0"?>
<root>
  <span><number>9.3</number> <code>protected</code> members</span>
  <span><number>9.4</number> miscellaneous members.</span>
</root>

Here is the desired output:

<?xml version="1.0"?>
<root>
  <span> <code>protected</code> members</span>
  <span> miscellaneous members.</span>
</root>

I want to output all of the elements and text of the original <span> element, 
but without the <number> element. I am using this for my xsl:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:xs="http://www.w3.org/2001/XMLSchema";
    exclude-result-prefixes="xs"
    version="2.0">

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/root">
        <root>
            <xsl:for-each select="span">
                <xsl:copy-of select="descendant::*[not(self::number)]"/>
            </xsl:for-each>
        </root>
    </xsl:template>

</xsl:stylesheet>

This is my current (incorrect) output:

<?xml version="1.0" encoding="UTF-8"?>
<root>
   <code>protected</code>
</root>

Any help or pointers would be appreciated. Thanks.

Rick Quatro
Carmen Publishing Inc.
585-366-4017
rick(_at_)frameexpert(_dot_)com





-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>