Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > What am I missing re: very simple XML->XML transform

Reply
Thread Tools

What am I missing re: very simple XML->XML transform

 
 
Duane Morin
Guest
Posts: n/a
 
      01-26-2004
Ok, I've got a situation where I have an XML that looks something like
this:
<A>
<B>
<C/>
</B>
<D>
<C/>
</D>
<E>
</E>
</A>
....
basically the relevant descriptor is "There are some instances of <C>
in the file in non-easily predictable spots."

What I want to do is transform this file so that it looks like this:
<A>
<B>
<C/><MyTag/>
</B>
<D>
<C/><MyTag/>
</D>
...
In other words "Find all <C> tags and insert <MyTag> after it."

I am at a loss as to how to do this. I can get the "Find all C's and
do this afterward..." but how to I say "And leave the rest of the file
exactly as it is?" Can I even do that? Do I have to explicitly say
"Find A, write A, find B, write B...find C, write C and then write
MyTag...."?? That can't be right, can it?
 
Reply With Quote
 
 
 
 
Marten Gaans
Guest
Posts: n/a
 
      01-26-2004
Duane Morin wrote:
....
> In other words "Find all <C> tags and insert <MyTag> after it."
>
> I am at a loss as to how to do this. I can get the "Find all C's and
> do this afterward..." but how to I say "And leave the rest of the file
> exactly as it is?" Can I even do that? Do I have to explicitly say
> "Find A, write A, find B, write B...find C, write C and then write
> MyTag...."?? That can't be right, can it?


start with the 'identity template', which copies your document recursively:

--
<?xml version="1.0" encoding="ISO-8859-1"?>

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

<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*" />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
--

and add templates for elements, you want modified/deleted... , in your case:

....
<xsl:template match="C">
<xsl:copy-of select=".">
<MyTag/>
</xsl:template>
....


m.

 
Reply With Quote
 
 
 
 
Duane Morin
Guest
Posts: n/a
 
      01-26-2004
Great! Thanks for the help! Unfortunately I get a SAXParseException,
"node in step pattern not implemented." It points at the first
match="node()|@*" line.

Is my SAX parser just out of date, or is this a DOM-only thing? We're
using jclark's, I think circa 1999. It's what was here when I got
here.

Duane



Marten Gaans <> wrote in message news:<>...
> <?xml version="1.0" encoding="ISO-8859-1"?>
>
> <xsl:stylesheet xmlnssl="http://www.w3.org/1999/XSL/Transform"
> version="1.0">
>
> <xsl:template match="node()|@*">
> <xsl:copy>
> <xsl:apply-templates select="node()|@*" />
> </xsl:copy>
> </xsl:template>
>
> </xsl:stylesheet>
> --
>
> and add templates for elements, you want modified/deleted... , in your case:
>
> ...
> <xsl:template match="C">
> <xsl:copy-of select=".">
> <MyTag/>
> </xsl:template>
> ...
>
>
> m.

 
Reply With Quote
 
Marten Gaans
Guest
Posts: n/a
 
      01-26-2004
Duane Morin wrote:
> Great! Thanks for the help! Unfortunately I get a SAXParseException,
> "node in step pattern not implemented." It points at the first
> match="node()|@*" line.


try to replace 'node()' with '*', shouldn't make a difference for your example.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help running a very very very simple code olivier.melcher Java 8 05-12-2008 07:51 PM
blocking I/O with javax.xml.parsers.DocumentBuilder.parse() and javax.xml.transform.Transformer.transform() jazzdman@gmail.com Java 1 03-27-2005 06:56 AM
very very very long integer shanx__=|;- C Programming 19 10-19-2004 03:55 PM
Quick Book file access very very very slow Thomas Reed Computer Support 7 04-09-2004 08:09 PM
very Very VERY dumb Question About The new Set( ) 's Raymond Arthur St. Marie II of III Python 4 07-27-2003 12:09 AM



Advertisments