Too much display from transformation

Here should go questions about transforming XML with XSLT and FOP.
oandie
Posts: 5
Joined: Thu May 12, 2005 4:31 pm

Too much display from transformation

Post by oandie »

Hi there,

I have a problem in transforming XML- data. Some elements are shown which I can't explain to myself why they are shown.
The source is in GML and i want to generate SVG.

<BPlanAuszug>
<wfs:FeatureCollection>
<gml:boundedBy>
<gml:Envelope>
<gml:pos>3566523.5 5950548</gml:pos>
<gml:pos>3566684 5950630.5</gml:pos>
</gml:Envelope>
</gml:boundedBy>
<gml:featureMember>
<xplan:BPlan gml:id="BPlan_0">
<xplan:name>Bebauungsplan B139</xplan:name>
<xplan:stadt>Hamburg</xplan:stadt>
<xplan:ebene xlink:href="#BPlanEbene_0"/>
</xplan:BPlan>
</gml:featureMember>
<gml:featureMember>
<xplan:BPlanEbene gml:id="BPlanEbene_0">
<xplan:ebene>0</xplan:ebene>
<xplan:fachobjekt xlink:href="#obj_0"/>
</xplan:BPlanEbene>
</gml:featureMember>
<gml:featureMember>
<xplan:RaeumlicherGeltungsbereich gml:id="obj_0">
<xplan:position>
<gml:MultiSurface>
<gml:surfaceMember>
<gml:Polygon>
<gml:exterior>
<gml:LinearRing>
<gml:pos>3479367.656 5889625.167</gml:pos>
<gml:pos>3479372.858 5889638.326</gml:pos>
<gml:pos>3479383.141 5889664.334</gml:pos>
....
</gml:LinearRing>
</gml:exterior>
</gml:Polygon>
</gml:surfaceMember>
</gml:MultiSurface>
</xplan:position>
</xplan:RaeumlicherGeltungsbereich>
</gml:featureMember>

This is how the data looks like. At least a few more points.
What I need are just the gml:pos- coordinates. After the transformation all gml:featureMember's which are placed before the one which contains the coordinates are shown in front of my string formattings.
Here comes the XSLT- source code:

<svg.....>
...
<xsl:apply-templates mode="Ebene"/>
...
</svg>

<xsl:template name="x_coord">
<!--<xsl:variable name="pointlist_x">
<xsl:value-of select="."/>
</xsl:variable>-->
<xsl:variable name="pointlist2" select="substring-before(.,' ')"/>
<xsl:variable name="pointlist2a" select="substring($pointlist2, 3, 8)"/>
<xsl:variable name="numberlist2c" select="number(($pointlist2a) div 1000)"/>

<xsl:value-of select="$numberlist2c"/>
</xsl:template>

<xsl:template name="y_coord">
<!--<xsl:variable name="pointlist_y">
<xsl:value-of select="."/>
</xsl:variable>-->
<xsl:variable name="pointlist3" select="substring-after(.,' ')"/>
<xsl:variable name="pointlist3a" select="substring($pointlist3, 3, 8)"/>
<xsl:variable name="numberlist3c" select="number(($pointlist3a) div 1000)"/>

<xsl:value-of select="$numberlist3c"/>

</xsl:template>

<xsl:template name="create_path">
<xsl:param name="style"/>

<path>
<xsl:attribute name="class">
<xsl:value-of select="$style"/>
</xsl:attribute>

<xsl:attribute name="d">
<xsl:for-each select="xplan:position/gml:MultiSurface/gml:surfaceMember/gml:Polygon/gml:exterior/gml:LinearRing/gml:pos">
<xsl:if test="position() = 1">
<xsl:text>M </xsl:text>
</xsl:if>
<xsl:choose>
<xsl:when test="position() != last()">
<xsl:call-template name="x_coord"/>
<xsl:text> </xsl:text>
<xsl:call-template name="y_coord"/>
<xsl:text> L </xsl:text>
</xsl:when>
<xsl:when test="position() = last()">
<xsl:call-template name="x_coord"/>
<xsl:text> </xsl:text>
<xsl:call-template name="y_coord"/>
<xsl:text> Z </xsl:text>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:attribute>

</path>

<xsl:template match="BPlanAuszug/wfs:FeatureCollection/gml:featureMember/xplan:RaeumlicherGeltungsbereich" mode="Ebene" >
<xsl:call-template name="create_path">
<!--<xsl:with-param name="feature" select="xplan:position/gml:MultiSurface/gml:surfaceMember/gml:Polygon/gml:exterior/gml:LinearRing/gml:pos"/>-->
<xsl:with-param name="style" select="'Gemeinde'"/>
<xsl:with-param name="style1" select="'clip'"/>
</xsl:call-template>
</xsl:template>

In my opinion the display should only contain the path- element with the coordinates. But maybe someone can show me what I have done wrong.

cheers

andy
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Andy,

Please provide cut down samples that are wellformed so we can be able to easily reproduce the problem. Your sample xml is not wellformed and the stylesheet is invalid...
Also it will help to see your current result and the expected result.

Best Regards,
George
oandie
Posts: 5
Joined: Thu May 12, 2005 4:31 pm

Post by oandie »

Hi George,

thanks for the reply. Sorry for the length of the source. I reduced it, even though it's still a bit long.....
the gml-file:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<BPlanAuszug xmlns:gml="http://www.opengis.net/gml" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xplan="http://www.interactive-instruments.de/xplanung" xmlns:wfs="http://www.opengis.net/wfs" >
<wfs:FeatureCollection>
<gml:Envelope>
<gml:pos>3566523.5 5950548</gml:pos>
<gml:pos>3566684 5950630.5</gml:pos>
</gml:Envelope>
<gml:featureMember>
<xplan:RaeumlicherGeltungsbereich>
<gml:LinearRing>
<gml:pos>3479367.656 5889625.167</gml:pos>
<gml:pos>3480531.106 5889488.451</gml:pos>
<gml:pos>3479367.656 5889625.167</gml:pos>
</gml:LinearRing>
</xplan:RaeumlicherGeltungsbereich>
</gml:featureMember>
</wfs:FeatureCollection>
</BPlanAuszug>

here comes the xslt- file:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:gml="http://www.opengis.net/gml"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:xplan="http://www.interactive-instruments.de/xplanung"
xmlns:xlink="http://www.w3.org/1999/xlink">
<xsl:output method="xml" indent="yes"
doctype-public="-//W3C//DTD SVG 1.1//EN" doctype-system=
"http://www.w3.org/Graphics/SVG/1.1/DTD/ ... 030114.dtd"/>

<xsl:template match="/">
<svg width="100%" height="100%" viewBox="0 0 650 450">
<xsl:apply-templates mode="Ebene" />
</svg>
</xsl:template>

<xsl:template name="x_coord">
<xsl:variable name="pointlist2" select="substring-before(.,' ')"/>
<xsl:variable name="pointlist2a" select="substring($pointlist2, 3, 8)"/>
<xsl:variable name="numberlist2c" select="number(($pointlist2a) div 1000)"/>
<xsl:value-of select="$numberlist2c"/>
</xsl:template>

<xsl:template name="y_coord">
<xsl:variable name="pointlist3" select="substring-after(.,' ')"/>
<xsl:variable name="pointlist3a" select="substring($pointlist3, 3, 8)"/>
<xsl:variable name="numberlist3c" select="number(($pointlist3a) div 1000)"/>
<xsl:value-of select="$numberlist3c"/>
</xsl:template>

<xsl:template name="create_path">
<g>
<path>
<xsl:attribute name="d">
<xsl:for-each select="gml:LinearRing/gml:pos">
<xsl:call-template name="x_coord">
<xsl:with-param name="pointlist_x" select="."/>
</xsl:call-template>
<xsl:text> </xsl:text>
<xsl:call-template name="y_coord">
<xsl:with-param name="pointlist_y" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:attribute>
</path>
</g>
</xsl:template>

<!--Raeumlicher Geltungsbereich-->
<xsl:template match="BPlanAuszug/wfs:FeatureCollection/gml:featureMember/xplan:RaeumlicherGeltungsbereich" mode="Ebene" >
<xsl:call-template name="create_path"/>
</xsl:template>
</xsl:stylesheet>

the current display:

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/ ... 030114.dtd">
<svg xmlns:gml="http://www.opengis.net/gml" xmlns:wfs="http://www.opengis.net/wfs" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xplan="http://www.interactive-instruments.de/xplanung" width="100%" height="100%" viewBox="0 0 650 450">3566523.5 59505483566684 5950630.5<g>
<path d="79.36765 89.6251680.5311 89.4884579.36765 89.62516"/>
</g></svg>

The output I want should be without the coordinates before the <g> element (3566523.5 59505483566684 5950630.5). So that just the formatted coordinates in the <path>- element are shown.
In my editor the files are well- formed. If not, please let me know.

cheers

andy
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Andy,

The XSLT specification defines a set of built in templates [1] that exist in any stylesheet even if they are not specified. For instance there is a builtin template that matches the text nodes and attributes and outputs their values.
If you overwrite that adding a template like below:
<xsl:template match="text()" mode="Ebene"/>
then you will get the expected result.

[1] http://www.w3.org/TR/xslt#built-in-rule

Best Regards,
George
oandie
Posts: 5
Joined: Thu May 12, 2005 4:31 pm

Post by oandie »

Hi George,

thanks for your help. It's working right now.
With the mode element I want to control the layers for drawing objects in SVG. So I ll need some more templates with mode.
Is there maybe a smarter way instead of overwriting the builtin template? Because I overwrote the builtin template for the Layer2 mode the same way as I did for the first one. In the end I would have 10 or more layers.
It should look like that:

Code: Select all

<xsl:apply-templates mode="Layer02" />
<xsl:apply-templates mode="Layer01"/>
At the bottom I am defining the objects which get an drawing order by mode. I guess this is more ordered.

cheers

andy
Post Reply