Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Xml to Xml transform problem

Reply
Thread Tools

Xml to Xml transform problem

 
 
@CL
Guest
Posts: n/a
 
      12-12-2006
Hi,all

I was confused with xml transform.
I had a xml file like:
<Details>
<names>
<name/>
<name/>
......or more <name/>
</names>

<orders>
<order/>
<order/>
.....or more <order/>
</orders/>

....or more element
</Details>

and the destination would be like:
<Details>
<Detail>
<name/>
<order/>
.....or more element
</Detail>

<Detail>
<name/>
<order/>
.....or more element
</Detail>

.....or more details
<Details>

the num of details may be as large as 2000,
first get the nums and simply selected use the [index],
as:
<xsl:template match="/">
<Details>
<detail>
<name>
<xsl:value-of select="/Details/names/name[1]"/>
</name>
<order>
<xsl:value-of select="/Details/orders/order[1]"/>
</order>
....more elements
</detail>
....more detail with the index
</Details>
</xsl:template >

when the num is lagrer than a num ,maybe 30,the JAXP would throw the
javax.xml.transform.TransformerConfigurationExcept ion: can't load
translet class "GregorSamsa"

so what can I do with it?
I had tried to use the for-each loop and template loop,but there is
always with the syntax error,
and can you help me£¿

thanks
Richard

 
Reply With Quote
 
 
 
 
@CL
Guest
Posts: n/a
 
      12-12-2006

briefly , I need the loop like :

for(int i=0;i<len;i++){
// create the detail
<detail>
<xsl:value-of select="/Details/detail/name[i]">
<xsl:value-of select="/Details/detail/order[i]">
.....
</detail>
}

thanks,
Richard

 
Reply With Quote
 
 
 
 
p.lepin@ctncorp.com
Guest
Posts: n/a
 
      12-12-2006

@CL wrote:
> I had a xml file like:
> <Details>
> <names>
> <name/>
> <name/>
> ......or more <name/>
> </names>
>
> <orders>
> <order/>
> <order/>
> .....or more <order/>
> </orders/>


That's, uh, not particularly well-formed.

> ....or more element
> </Details>


> the num of details may be as large as 2000,
> first get the nums and simply selected use the [index],


Er, what? Do you mean you need to group name, order etc.
elements depending on their position?

> <xsl:template match="/">
> <Details>
> <detail>
> <name>
> <xsl:value-of
> select="/Details/names/name[1]"/>
> </name>
> <order>
> <xsl:value-of
> select="/Details/orders/order[1]"/>
> </order>
> ....more elements
> </detail>
> ....more detail with the index
> </Details>
> </xsl:template >


You're kidding, aren't you? You wrote that 2000 times or
so? Don't mention this to your team leader, but if *I* were
your team leader, they'd never find your body. What's the
point of using XSLT if you're not actually using it?

> when the num is lagrer than a num ,maybe 30,the JAXP
> would throw the
> javax.xml.transform.TransformerConfigurationExcept ion:
> can't load translet class "GregorSamsa"


Probably something's wrong with your transformation, but
you'd better ask that question on a Java newsgroup.

> I had tried to use the for-each loop


for-each is not a loop.

> and template loop,


Do you mean recursive templates? I would expect your
processor to die horribly trying to cope up with 2000-deep
recursion, unless it happens to be capable of optimizing
tail recursion, and unless your transformation happens to
be tail-recursive.

> but there is always with the syntax error,


I think something's 'there is always with the syntax error'
in this sentence.

> and can you help me£¿


<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/Details">
<xsl:copy>
<xsl:apply-templates select="*[1]/*" mode="Detail"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*" mode="Detail">
<xsl:variable name="position" select="position()"/>
<Detail>
<xsl:apply-templates
select="../../*/*[position()=$position]"
mode="copy"/>
</Detail>
</xsl:template>
<xsl:template match="*" mode="copy">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>

--
Pavel Lepin

 
Reply With Quote
 
@CL
Guest
Posts: n/a
 
      12-12-2006

" дµÀ£º
> > the num of details may be as large as 2000,
> > first get the nums and simply selected use the [index],

>
> Er, what? Do you mean you need to group name, order etc.
> elements depending on their position?
>
> > <xsl:template match="/">
> > <Details>
> > <detail>
> > <name>
> > <xsl:value-of
> > select="/Details/names/name[1]"/>
> > </name>
> > <order>
> > <xsl:value-of
> > select="/Details/orders/order[1]"/>
> > </order>
> > ....more elements
> > </detail>
> > ....more detail with the index
> > </Details>
> > </xsl:template >

>
> You're kidding, aren't you? You wrote that 2000 times or
> so? Don't mention this to your team leader, but if *I* were
> your team leader, they'd never find your body. What's the
> point of using XSLT if you're not actually using it?


ya,it's my first time to use xslt,
at first the depth was low,so I used a function to generated it simply,

> Do you mean recursive templates? I would expect your
> processor to die horribly trying to cope up with 2000-deep
> recursion, unless it happens to be capable of optimizing
> tail recursion, and unless your transformation happens to
> be tail-recursive.
>
> > but there is always with the syntax error,

>
> I think something's 'there is always with the syntax error'
> in this sentence.
>
> > and can you help me£¿

>
> <xsl:stylesheet version="1.0"
> xmlnssl="http://www.w3.org/1999/XSL/Transform">
> <xsl:template match="/Details">
> <xsl:copy>
> <xsl:apply-templates select="*[1]/*" mode="Detail"/>
> </xsl:copy>
> </xsl:template>
> <xsl:template match="*" mode="Detail">
> <xsl:variable name="position" select="position()"/>
> <Detail>
> <xsl:apply-templates
> select="../../*/*[position()=$position]"
> mode="copy"/>
> </Detail>
> </xsl:template>
> <xsl:template match="*" mode="copy">
> <xsl:copy-of select="."/>
> </xsl:template>
> </xsl:stylesheet>
>
> --
> Pavel Lepin


I'm sorry for I can't know all about your sent,but I'll try to,
thanks very much.

regards,
Richard

 
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
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
How to use XSLT to transform XML according to the data in another XML ai2003lian@yahoo.com XML 1 02-02-2005 05:07 PM
How to use XSLT to transform XML according to the data in another XML ai2003lian@yahoo.com XML 0 02-02-2005 04:57 PM
What am I missing re: very simple XML->XML transform Duane Morin XML 3 01-26-2004 05:44 PM
What parses the xml/xsl transform in asp.net? System.xml NOT msxml? KathyB ASP .Net 0 06-25-2003 05:03 PM



Advertisments