Xml to Xml transform problem

@

@CL

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.TransformerConfigurationException: 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
 
@

@CL

briefly , I need the loop like :

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

thanks,
Richard
 
P

p.lepin

@CL said:
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.TransformerConfigurationException:
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"
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>
 
@

@CL

"(e-mail address removed) дµÀ£º
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"
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>

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

regards,
Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,007
Messages
2,570,266
Members
46,864
Latest member
DaniEbswor

Latest Threads

Top