newbie xslt namespace question

D

disen

Hi,
i try to generate from a gml-file (geography markup language) an
svg-file using java (xalan) (i'm using java 1.4.2)

My problem is now dealing with namespaces in xslt (at least this is
what i guess).

the gml-file looks like this:

<?xml version='1.0' encoding='UTF-8'?>
<ogr:FeatureCollection xmlns:gml='http://www.opengis.net/gml'
xmlns:xsi='http://www.w3c.org/2001/XMLSchema-instance'
xmlns:eek:gr='http://ogr.maptools.org/'
xmlns='http://gdal.velocet.ca/ogr'
xsi:schemaLocation='http://gdal.velocet.ca/ogr defol.xsd'>
...
<gml:featureMember>
<defol>
<cat>1</cat>
<area>2668790.35979</area>
<perimeter>8356.95744649</perimeter>
<sites_for_>2</sites_for_>
<sites_for1>1</sites_for1>
<site_id>10</site_id>
<oid_>2</oid_>
<objectid>59</objectid>
<site_id_1>10</site_id_1>
<ogr:geometryProperty>
<gml:coordinates>796418.625,...


the xsl-file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:gml="http://www.opengis.net/gml"
xmlns:eek:gr="http://gdal.velocet.ca/ogr"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!-- root template -->
<xsl:template match="/">
<svg width="400" height="400">
<g>
<xsl:apply-templates />
</g>
</svg>
</xsl:template>
....


<!-- toplevel template -->
<xsl:template match="gml:featureMember">
test1
<xsl:apply-templates select="ogr:defol"/>
</xsl:template>

<!-- named templates -->
<!-- namespaces, also the default ns, must be given explicitely
-->
<xsl:template match="ogr:defol">
test2
<xsl:apply-templates select="ogr:geometryProperty"/>
<xsl:apply-templates select="ogr:site_id"/>
<xsl:apply-templates select="ogr:cat"/>
</xsl:template>

<xsl:template match="ogr:cat">
cat = <xsl:value-of select="."/>
</xsl:template>

<xsl:template match="ogr:geometryProperty">
test3
<xsl:apply-templates select="gml:polygon"/>
</xsl:template>
...

The result is:
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:eek:gr="http://gdal.velocet.ca/ogr"
xmlns:gml="http://www.opengis.net/gml" height="400" width="400"><g>


test1

test2

cat = 1
</g></svg>


the problem i have now is that the element ogr:geometryProperty is not
matched by the template. The problem seems to be the ogr-prefix (which
is the default namespace in the gml-file).

Any ideas?
Thanx very much in advance

Dani
 
J

Joris Gillis

Hi,
the problem i have now is that the element ogr:geometryProperty is not
matched by the template. The problem seems to be the ogr-prefix (which
is the default namespace in the gml-file).

Apparently, 'http://gdal.velocet.ca/ogr' is the default namespace in the gml-file. The 'ogr' prefix declares a non-default namespace (viz. 'http://ogr.maptools.org/')
Therefore the 'cat' element and the 'ogr:geometryProperty' element can never be matched (in Xpath) with one single namespace (prefix).

You'll have to define yet another prefix in the XSLT that links to 'http://ogr.maptools.org/' in order to match the 'geometryProperty' elment with a prefix.


e.g.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:gml="http://www.opengis.net/gml"
xmlns:eek:gr="http://gdal.velocet.ca/ogr"
xmlns:OGR='http://ogr.maptools.org/'
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xsl:template match="ogr:defol">
test2
<xsl:apply-templates select="OGR:geometryProperty"/>
<xsl:apply-templates select="ogr:site_id"/>
<xsl:apply-templates select="ogr:cat"/>
</xsl:template>

<xsl:template match="OGR:geometryProperty">
test3
<xsl:apply-templates select="gml:polygon"/>
</xsl:template>

</xsl:stylesheet>

regards,
 
D

Dani Isenegger

Hi Joris,
thanks this works.
(I don't quite get why: i guess i have to get a little bit deeper into
that stuff) :)-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top