Subject: problem transforming XML using xslt
Posted By: micky3248 Post Date: 8/10/2006 8:32:12 AM
Hi,

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


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

    <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>
            <!-- Process child-nodes -->
        <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

Reply By: mhkay Reply Date: 8/10/2006 12:36:03 PM
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
Reply By: micky3248 Reply Date: 8/10/2006 1:05:51 PM
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

Reply By: micky3248 Reply Date: 8/18/2006 2:40:26 AM
Hi Thx a lot, it works the way I want it. Unfortunately I'm still having problems. I wanted to use such a code:

<xsl:template match="ZMSTextarea">

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

Reply By: mhkay Reply Date: 8/18/2006 2:49:14 AM
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
Reply By: micky3248 Reply Date: 8/18/2006 3:05:31 AM
Another problem: I have a list in this form:

<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

Reply By: mhkay Reply Date: 8/18/2006 3:48:22 AM
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
Reply By: micky3248 Reply Date: 8/18/2006 3:52:48 AM
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


Go to topic 48518

Return to index page 200
Return to index page 199
Return to index page 198
Return to index page 197
Return to index page 196
Return to index page 195
Return to index page 194
Return to index page 193
Return to index page 192
Return to index page 191