XML to XML newbee help

Discussion in 'XML' started by Adam, Jul 1, 2004.

  1. Adam

    Adam Guest

    Hi, Me very confused. I have some XML that I want to convert to a more
    basic XML. I have put an example of what I have and what I want, I
    have used XSL to convert XML to HTML, but never this way.

    The <item numberingtext="10.01.01 "> I want in the para tag I
    think, but if it has to be it own tag, no worrys.

    Any help would be fantastic

    Example of what I have:
    =========================
    <?xml version="1.0" encoding="UTF-8" ?>
    <document xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:html="http://www.w3.org/HTML/1998/html4" xml:lang="en"
    style="widows: 0; orphans: 0; word-break-inside: normal;
    \-ilx-endnote-position: sectionbottom; \-ilx-endnote-style-type:
    lower-alpha; \-ilx-footnote-position: pagebottom;
    \-ilx-footnote-numbering-policy: continuous;
    \-ilx-endnote-numbering-policy: continuous; \-ilx-footnote-style-type:
    decimal;\-ilx-block-border-mode: merge;">
    <part style="page: pageStyle1;">
    <par class="Ahead">Duis autem vel eum iriure dolor in hendrerit in
    </par>
    <par class="Bhead">vulputate velit esse consequat</par>
    <par class="Normal" style="font-size: 12.0pt;"></par>
    <list style="margin-left: 18.0mm; list-style-type: decimal;
    \-ilx-list-group: 4; \-ilx-marker-align: left; \-ilx-marker-format:
    &quot;%0.%1.%0&quot;; \-ilx-marker-offset: -1020tw;
    \-ilx-marker-follow: tab;">
    <item numberingtext="10.01.01 ">
    <par class="MainText" style="\-ilx-tab-stops: &quot;left blank
    0tw&quot;;">Lorem ipsum dolor sit amet,
    <link xlink:type="simple" xlink:show="replace"
    xlink:actuate="onRequest" xlink:href="http://www.apple.com">
    <inline class="Hyperlink">consectetuer</inline>
    </link> adipiscing elit, sed diam nonummy nibh euismod
    <inline class="reference">tincidunt</inline> ut laoreet dolore
    magna aliquam erat volutpat Ut wisi eiim ad minim veniam, quis nostrud
    exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea
    commodo consequat (B-1664-0010). Duis lobortis autem vel eum iriure
    dolor in hendrerit in vulputate velit esse
    <link xlink:type="simple" xlink:show="replace"
    xlink:actuate="onRequest" xlink:href="http://www.apple.com">
    <inline class="Hyperlink">molestie</inline>
    </link> consequat, vel illum dolore eu feugiat nulla facilisis at
    vero eros et accumsan et iusto odio dignissim qui blandit praesent
    luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
    </par>
    </item>
    </list>
    </part>
    </document>




    =========================
    This is what I want:
    =========================
    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <Ahead>Duis autem vel eum iriure dolor in hendrerit in</Ahead>
    <Bhead>vulputate velit esse consequat</Bhead>
    <para>10.01.01 Lorem ipsum dolor sit amet,
    <link href="http://www.apple.com">consectetuer</link> adipiscing
    elit, sed diam nonummy nibh euismod
    ut laoreet dolore magna aliquam erat volutpat Ut wisi eiim ad minim
    veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl
    ut aliquip ex ea commodo consequat (B-1664-0010). Duis lobortis autem
    vel eum iriure dolor in hendrerit in vulputate velit esse
    <link href="http://www.apple.com">consectetuer</link> consequat, vel
    illum dolore eu feugiat nulla facilisis at vero eros et accumsan et
    iusto odio dignissim qui blandit praesent luptatum zzril delenit augue
    duis dolore te feugait nulla facilisi.
    </para>
    </root>
    Adam, Jul 1, 2004
    #1
    1. Advertising

  2. Adam

    Baldo Guest

    Ehy, ma il 1 Jul 2004 02:29:49 -0700 (
    (Adam)) ha detto:

    >Example of what I have:



    please simplify your from-XML and to-XML and i'll help u.

    --
    baldo
    Baldo, Jul 3, 2004
    #2
    1. Advertising

  3. Adam

    Adam Guest

    Hi,

    I want to convert the XML at the top using XSL to cleaner XML, to then
    be used in other aplications.

    Can this be done?.


    Thanks



    Baldo <> wrote in message news:<>...
    > Ehy, ma il 1 Jul 2004 02:29:49 -0700 (
    > (Adam)) ha detto:
    >
    > >Example of what I have:

    >
    >
    > please simplify your from-XML and to-XML and i'll help u.
    Adam, Jul 4, 2004
    #3
  4. Adam

    Andy Dingley Guest

    (Adam) wrote in message news:<>...
    > Hi, Me very confused. I have some XML that I want to convert to a more
    > basic XML. I have put an example of what I have and what I want,


    Try this:

    Notes:
    - I'm ingnoring some whitespace issues that are rarely significant.
    You'd need to supply a better spec before going there.

    - I guess the text of the second link in your example was a typo.

    - This is an impossible problem to solve, as a general case from one
    example. I can make it work (quite easily) for that one case, but a
    couple of examples don't _define_ a mapping (I had to guess at this,
    and it's a 50:50 guess between whether to map <item> or <par
    class="MainText"> as the output <para>).

    As a reductio ad absurdum, I could simply have wrapped your output
    example in a <xsl:template> element (literal text and all !) and
    called that a valid solution to the stated question. You see the
    problem ?


    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet
    version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    exclude-result-prefixes="xlink"
    >


    <xsl:eek:utput method="xml" version="1.0" encoding="UTF-8" indent="yes"/>


    <xsl:template match="link" >
    <link href="{@xlink:href}" ><xsl:value-of select=".//text()"
    /></link>
    </xsl:template>

    <xsl:template match="par[@class='Normal']" />

    <xsl:template
    match="par[@class='MainText']" >
    <para>
    <xsl:value-of select="translate (parent::item/@numberingtext,
    ' ', ' ')" />
    <xsl:apply-templates select="* | text()" />
    </para>
    </xsl:template>


    <xsl:template
    match="par[@class and not (@class = 'Normal' or @class =
    'MainText')]" >
    <xsl:element name="{./@class}" ><xsl:value-of select="text()"
    /></xsl:element>
    </xsl:template>


    <xsl:template match="document/part" >
    <root>
    <xsl:apply-templates select="*" />
    </root>
    </xsl:template>

    </xsl:stylesheet>
    Andy Dingley, Jul 5, 2004
    #4
  5. Adam

    Adam Guest

    Thank you very much, will give this a go, and let you know how I get on.



    Again Thanks


    Adam
    Adam, Jul 5, 2004
    #5
  6. Adam

    Adam Guest

    Hi Andy

    Thanks that's fantastic, works just the way I wanted it to do.


    Adam
    Adam, Jul 6, 2004
    #6
    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.
Similar Threads
  1. Sascha Lauterbach

    Newbee needs Help on NetBeans

    Sascha Lauterbach, Aug 16, 2004, in forum: Java
    Replies:
    3
    Views:
    10,187
    Mark Murphy
    Aug 17, 2004
  2. Klaus Kragelund

    Newbee help - strange frame in a box

    Klaus Kragelund, Oct 9, 2005, in forum: HTML
    Replies:
    2
    Views:
    323
    Klaus Kragelund
    Oct 10, 2005
  3. Replies:
    0
    Views:
    382
  4. jstreet10
    Replies:
    1
    Views:
    336
    Sean Ross
    Dec 3, 2003
  5. Replies:
    5
    Views:
    416
Loading...

Share This Page