Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old August 10th, 2006, 08:32 AM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default problem transforming XML using xslt

Hi,

I'm experiencing problems with XSL transformation. I have an XML file that looks like this:

Code:
<ZMSRubrik id="e95">
    <title><lang id="ger"><![CDATA[Here a title]]></lang></title>
    <ZMSTextarea id="e74"><text><lang id="ger"><![CDATA[Here a text]]></lang></text></ZMSTextarea>
    <ZMSRubrik id="e95">
        <title><lang id="ger"><![CDATA[Here Titel2]]></lang></title>
        <ZMSTextarea id="e74"><text><lang id="ger"><![CDATA[Text2]]></lang></text></ZMSTextarea>
    </ZMSRubrik>
</ZMSRubrik>
I want to transform this for FOP. So I use this XSL file:
Code:
    <fo:root>
        <fo:layout-master-set>
            <fo:simple-page-master master-name="A4">
                             ......
            </fo:simple-page-master>
        </fo:layout-master-set>
                <xsl:apply-templates />
    </fo:root>
<xsl:template match="ZMS|ZMSRubrik|ZMSDocument">
        <fo:page-sequence master-reference="A4">
            <fo:flow flow-name="xsl-region-body">
                <xsl:for-each select="title/lang">
                    <fo:block>
                        <xsl:value-of select="." />
                    </fo:block>
                </xsl:for-each>
                <xsl:apply-templates select="*[ZMSTextArea|ZMSGraphic]"/> 
            </fo:flow>
        </fo:page-sequence>

        <xsl:apply-templates select="*[ZMSRubrik|ZMSDocument]"/>
</xsl:template>
<xsl:template match="ZMSTextarea">
   here the transformation for textarea
</xsl:template>
<xsl:template match="ZMSGraphic">
   here the transformation for graphics
</xsl:template>
Using this, I thought I should get one page-sequence for each ZMSRubrik, and each page-sequence shouldn't be a child of another page-template. Unfortunately it doesn't seem to work. The 2 other templates (ZMSTextarea and ZMSGraphic) are for elements of a page and they work well. I really have no idea why my code doesn't work.

Thx for any help. Micky

  #2 (permalink)  
Old August 10th, 2006, 12:36 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I suspect you are under the impression that

select="*[ZMSTextArea|ZMSGraphic]"

will process children that are named ZMSTextArea or ZMSGraphic.

In fact it will process all children that have a child named ZMSTextArea or ZMSGraphic.

Perhaps you want

select="ZMSTextArea | ZMSGraphic"

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #3 (permalink)  
Old August 10th, 2006, 01:05 PM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh, I think I misunderstood it. I just begun 2 weeks ago, so I still don't understand everything. I'll try it next week after my holiday... Thx Micky

  #4 (permalink)  
Old August 18th, 2006, 02:40 AM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Thx a lot, it works the way I want it. Unfortunately I'm still having problems. I wanted to use such a code:

Code:
<xsl:template match="ZMSTextarea">


    <xsl:variable name="format">
        <xsl:choose>
            <xsl:when test="format='headline_1'">headline_1</xsl:when>
            <xsl:when test="format='headline_2'">headline_2</xsl:when>
            <xsl:when test="format='headline_3'">headline_3</xsl:when>
            <xsl:when test="format='headline_4'">headline_4</xsl:when>
            <xsl:when test="format='headline_5'">headline_5</xsl:when>
            <xsl:when test="format='headline_6'">headline_6</xsl:when>
            <xsl:when test="format='indented_block'">indented_block</xsl:when>
            <xsl:when test="format='emphasis'">emphasis</xsl:when>
            <xsl:when test="format='caption'">caption</xsl:when>
            <xsl:when test="format='unordered_list'">unordered_list</xsl:when>
            <xsl:otherwise>standard</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

    <xsl:element name="fo:block" use-attribute-sets="{$format}">
        <xsl:for-each select="text/lang">
            <xsl:value-of select="." disable-output-escaping="yes"/>
        </xsl:for-each>
    </xsl:element>

</xsl:template>
but saxon is giving an error: "No attribute-set exists named {$format}"
Isn't it possible to use a variable instead of a fix name for use-attribute-sets?
  #5 (permalink)  
Old August 18th, 2006, 02:49 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Isn't it possible tu use a variable instead of a fix name for use-attribute-sets?

No, it isn't. Just as in C or Java, certain things have to be known at compile time - names of variables, functions, templates, and attribute sets are some examples. You can only use the curly-bracket notation in attributes where XSLT explicitly permits it.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #6 (permalink)  
Old August 18th, 2006, 03:05 AM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Another problem: I have a list in this form:

Code:
<ZMSTextarea id="e74">
<format><![CDATA[unordered_list]]></format>
<attr_dc_coverage><![CDATA[global.ger]]></attr_dc_coverage>
<text>
<lang id="ger"><![CDATA[Was ist ein Content Management System
Was ist das ZMS, was ist Zope
Wie komme ich zu so einem System für meine Abteilung
Wie lautet die Adresse
Welche Adressen kann ich verwenden 
Woher bekomme ich die Adresse
Was ist die öffentliche Adresse, was ist die Adresse für die Wartung
Wie lauten meine Login-Daten
Wie komme ich zu einem Design
Kann ich ein Design anpassen
...]]></lang></text>
<active>
<lang id="ger">1</lang></active></ZMSTextarea>
The listitems are only in a new line. How kann I tell xsl, that each line is a ney item?

Thx in advance nico

  #7 (permalink)  
Old August 18th, 2006, 03:48 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I can't see what the list items in your source are.

In XSLT 2.0 you can split text into lines using the tokenize() function. To see how it's done in 1.0, take a look at the str:tokenize recursive template at www.exslt.org

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #8 (permalink)  
Old August 18th, 2006, 03:52 AM
Registered User
 
Join Date: Aug 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael,

If you have any tipps where I could look at, so I do not need to ask you each time, it would be good.

Thx for all the help. Regards Nico



Similar Threads
Thread Thread Starter Forum Replies Last Post
Show CURRENT DATE when transforming XML using XSLT richieWolf XSLT 0 October 20th, 2007 07:47 PM
Exception when transforming using XSLT ksskumar XSLT 5 October 10th, 2006 06:20 AM
Transforming XML data in an ASP file using XSLT hussainm Classic ASP XML 0 May 31st, 2006 03:21 PM
Please help, xml transforming using xslt !!! daula7 XSLT 0 May 11th, 2006 01:29 PM
Transforming a result tree with yet another Xslt ballo XSLT 2 March 7th, 2006 09:42 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.