Re: XSLT problems ...

Discussion in 'XML' started by Marrow, Jul 4, 2003.

  1. Marrow

    Marrow Guest

    Hi Martin,

    At the moment your XML is not well-formed - because you have namespace
    prefixes where the namespace is not declared (you will have to get this
    changed - because if it isn't well-formed XML then it just isn't XML at
    all).

    Assuming that you had well-formed XML like...

    == XML =======================================
    <?xml version="1.0"?>
    <dummy xmlns:a="aaa" xmlns:b="bbb">
    <a:p>
    <a:identiy>
    Caption
    </a:identiy>
    <a:text>
    1 first caption
    </a:text>
    </a:p>
    <b:border>
    <a:p>
    <a:text>
    here is a lot of text ....
    </a:text>
    </a:p>
    </b:border>
    <a:p>
    <a:identiy>
    Caption
    </a:identiy>
    <a:text>
    2 second caption
    </a:text>
    </a:p>
    <b:border>
    <a:p>
    <a:text>
    here is a lot of text ....
    </a:text>
    </a:p>
    </b:border>
    </dummy>
    == end of XML ================================

    Then something like (as a starting point)...

    == XSL =======================================
    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" exclude-result-prefixes="match_a match_b"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:match_a="aaa" xmlns:match_b="bbb">
    <xsl:eek:utput method="xml"/>
    <xsl:template match="/">
    <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="dummy">
    <final>
    <xsl:apply-templates select="match_a:p"/>
    </final>
    </xsl:template>

    <xsl:template match="match_a:p">
    <paragraph>
    <caption>
    <xsl:value-of select="match_a:text"/>
    </caption>
    <content>
    <xsl:value-of
    select="following-sibling::match_b:border[1]/match_a:p/match_a:text"/>
    </content>
    </paragraph>
    </xsl:template>

    </xsl:stylesheet>
    == end of XSL ================================

    Hope this helps
    Marrow
    http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    http://www.topxml.com/Xselerator




    "Buchleitner Martin" <> wrote in message
    news:...
    > [xpost: comp.text.xml, microsoft.public.xsl]
    >
    > Hi!
    >
    > My Problem:
    > I have to use XSLT to transfer a XML-file to be valid to a certain DTD.
    > I can not change the XML-file or the DTD ...
    > My XML-File looks like:
    > <dummy>
    > <a:p>
    > <a:identiy>
    > Caption
    > </a:identiy>
    > <a:text>
    > 1 first caption
    > </a:text>
    > </a:p>
    > <b:border>
    > <a:p>
    > <a:text>
    > here is a lot of text ....
    > </a:text>
    > </a:p>
    > </b:border>
    > <a:p>
    > <a:identiy>
    > Caption
    > </a:identiy>
    > <a:text>
    > 2 second caption
    > </a:text>
    > </a:p>
    > <b:border>
    > <a:p>
    > <a:text>
    > here is a lot of text ....
    > </a:text>
    > </a:p>
    > </b:border>
    > </dummy>
    >
    > I have to get a similar XML like this
    > <final>
    > <paragraph>
    > <caption>
    > 1 first caption
    > </caption>
    > <content>
    > here is a lot of text ....
    > </content>
    > </paragraph>
    > <paragraph>
    > <caption>
    > 2 second caption
    > </caption>
    > <content>
    > here is a lot of text ....
    > </content>
    > </paragraph>
    > </final>
    >
    > My Problem is that either i geht listed all a:p/a:text elements each time

    in
    > paragraph/caption or i get listed all b:border/a:p/a:text elements ...
    >
    > Has anybody an idea how to solve this?
    > That a:p and b:border would be matched together?
    >
    >
    > TIA, Martin
     
    Marrow, Jul 4, 2003
    #1
    1. Advertising

  2. "Marrow" <> wrote in
    news:A9cNa.23120$:

    Marrow's solution is a good one, but for the sake of accuracy...

    [...]

    > At the moment your XML is not well-formed - because you have
    > namespace prefixes where the namespace is not declared (you will
    > have to get this changed - because if it isn't well-formed XML
    > then it just isn't XML at all).


    The original XML file *is* well-formed...but it isn't compatible with
    a namespace-aware processor. According to the XML 1.0 specification
    (see the note in section 2.3), the colon is a name character, but
    *should not* (not "must not") be used unless designating a namespace.
    XML processors should nevertheless treat the colon as a name
    character.

    --
    a. m. slotnik
     
    arnold m. slotnik, Jul 4, 2003
    #2
    1. Advertising

  3. "Marrow" <> wrote in message news:<A9cNa.23120$>...

    Hi!
    >
    > At the moment your XML is not well-formed - because you have namespace
    > prefixes where the namespace is not declared (you will have to get this
    > changed - because if it isn't well-formed XML then it just isn't XML at
    > all).


    I had this already in my definition - thanks for reminding :)

    > Hope this helps


    It helped :)

    but my problems are still alive because i got a new dtd :(
    e.g.:
    <?xml version="1.0"?>
    <dummy xmlns:a="aaa" xmlns:b="bbb">
    <a:p>
    <a:identiy>
    essay
    </a:identiy>
    <a:text>
    this is my essay
    </a:text>
    <a:p>
    <a:identiy>
    Caption
    </a:identiy>
    <a:text>
    1 first caption
    </a:text>
    </a:p>
    <b:border>
    <a:p>
    <a:text>
    here is a lot of text ....
    </a:text>
    </a:p>
    </b:border>
    <a:p>
    <a:identiy>
    Caption
    </a:identiy>
    <a:text>
    2 second caption
    </a:text>
    </a:p>
    <b:border>
    <a:p>
    <a:text>
    here is a lot of text ....
    </a:text>
    </a:p>
    </b:border>
    </dummy>

    This should be transformed into
    <final>
    <essay>
    ... same stuff like before ...
    </essay>
    <final>

    And in this new DTD there are certain elements who have this property...
    last but not least - they are many nested elements of them :(
    and my knowledge of xslt and xpath lacks a lot ...


    Thanks anyway, Martin
     
    Buchleitner Martin, Jul 4, 2003
    #3
    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. Stylus Studio
    Replies:
    0
    Views:
    694
    Stylus Studio
    Aug 3, 2004
  2. Benjamin Hillsley
    Replies:
    3
    Views:
    1,693
    Dimitre Novatchev
    Sep 25, 2003
  3. ted
    Replies:
    1
    Views:
    626
    Laurens
    Jan 26, 2004
  4. Replies:
    2
    Views:
    726
    Henry S. Thompson
    Oct 19, 2005
  5. Replies:
    4
    Views:
    684
Loading...

Share This Page