Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 12th, 2006, 07:35 AM
@CL
Guest
 
Posts: n/a
Default Xml to Xml transform problem

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

  #2  
Old December 12th, 2006, 08:15 AM
@CL
Guest
 
Posts: n/a
Default Re: Xml to Xml transform problem


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

  #3  
Old December 12th, 2006, 08:15 AM
p.lepin@ctncorp.com
Guest
 
Posts: n/a
Default Re: Xml to Xml transform problem


@CL wrote:
Quote:
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.
Quote:
....or more element
</Details>
Quote:
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?
Quote:
<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?
Quote:
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.
Quote:
I had tried to use the for-each loop
for-each is not a loop.
Quote:
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.
Quote:
but there is always with the syntax error,
I think something's 'there is always with the syntax error'
in this sentence.
Quote:
and can you help me£¿
<xsl:stylesheet version="1.0"
xmlns:xsl="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

  #4  
Old December 12th, 2006, 08:55 AM
@CL
Guest
 
Posts: n/a
Default Re: Xml to Xml transform problem


"p.lepin@ctncorp.com дµÀ£º
Quote:
Quote:
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?
>
Quote:
<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,
Quote:
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.
>
Quote:
but there is always with the syntax error,
>
I think something's 'there is always with the syntax error'
in this sentence.
>
Quote:
and can you help me£¿
>
<xsl:stylesheet version="1.0"
xmlns:xsl="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

 

Bookmarks

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles