Xml to Xml transform problem

Discussion in 'XML' started by @CL, Dec 12, 2006.

  1. @CL

    @CL Guest

    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, Dec 12, 2006
    #1
    1. Advertising

  2. @CL

    @CL Guest

    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
     
    @CL, Dec 12, 2006
    #2
    1. Advertising

  3. @CL

    Guest

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

    --
    Pavel Lepin
     
    , Dec 12, 2006
    #3
  4. @CL

    @CL Guest

    " дµÀ£º
    > > 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>
    >
    > --
    > Pavel Lepin


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

    regards,
    Richard
     
    @CL, Dec 12, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page