XSLT problems ...

XSLT problems ...

Post by Buchleitner Mart » Sat, 05 Jul 2003 18:06:47



[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

 
 
 

XSLT problems ...

Post by Marro » Sat, 05 Jul 2003 18:54:42


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.veryComputer.com/;
 xmlns:match_a="aaa" xmlns:match_b="bbb">
<xsl:output 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.veryComputer.com/ - home of Xselerator (XSLT IDE and de*)
http://www.veryComputer.com/


Quote:> [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


 
 
 

XSLT problems ...

Post by arnold m. slotni » Sat, 05 Jul 2003 23:15:49




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

[...]

Quote:> 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

 
 
 

XSLT problems ...

Post by Buchleitner Mart » Sat, 05 Jul 2003 23:18:10


Hi!

Quote:

> 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 :)

Quote:> 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

 
 
 

XSLT problems ...

Post by Oleg Tkachenk » Mon, 07 Jul 2003 17:59:02



> 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?

Please, provide some examples, it's not really clear what do you mean.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel
 
 
 

1. XSLT: Problem using variable in XPath statement

I'm having a problem using a variable in an XPath statement.  What I'm
trying to do is fairly simple, but damn it if I can get it to work
:-).

The essential details are as follows:

Named lists of books, and I can make a list out of other lists, as in
the GroupBookList definition

<BookInfo>

   <BookList>
      <Name>PhysicsBooks</Name>
      <Items>
         <Book>...</Book>
         <Book>...</Book>
          ...
      </Items>
   </BookList>

   <BookList>
      <Name>BiologyBooks</Name>
      <Items>
         <Book>...</Book>
         <Book>...</Book>
          ...
      </Items>
   </BookList>

   <GroupBookList>
      <Name>ScienceBooks</Name>
      <Items>
         <BookList>PhysicsBooks</BookList>
         <BookList>BiologyBooks</BookList>
      </Items>
   </GroupBookList>

</BookInfo>

I've got a template that can process a normal booklist of books to
generate some HTML.  For the GroupBookLists, for each reference to
normal booklist it contains, I want to apply that same template... so
for the science books group, it'd generate the HTML that concatenates
the HTML for the PhysicsBooks and BiologyBooks lists.  To implement
this, in the template matching on group booklists, I use a for-each to
iterate through Items/BookList, and within the for-each have the the
following statements:

   <xsl:variable name="bookListName">
      <xsl:value-of select="." />
   </xsl:variable>

   <xsl:apply-templates
       select="/BookInfo/BookList[Name = '$bookListName']" />

This doesn't work.  The bookListName variable has the correct value,
but for whatever reason it's not putting the correct value into the
XPath statement... (I know the XPath statement is correct because if I
put a literal value in there for the bookListname it works
correctly...)  I've also tried various variations on all this but I
can't get anything to work...

Any suggestions would be much appreciated.

2. Fat32 and Fat16 compatible?

3. XSLT Problem

4. New CAD Web Magazine

5. XSLT: problem with transforming for a new namespace

6. Dual boot

7. xslt: problem with the sum function

8. what is the best financial app ?

9. XSLT Problem

10. XSLT problem: entity references inside attribute values

11. XSLT problem

12. Complex xslt problem: adding hierarchies

13. XSLT problem can you help