newbie xslt namespace question

Discussion in 'XML' started by disen, Jan 3, 2005.

  1. disen

    disen Guest

    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
     
    disen, Jan 3, 2005
    #1
    1. Advertising

  2. disen

    Joris Gillis Guest

    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,

    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Spread the wiki (http://www.wikipedia.org)
     
    Joris Gillis, Jan 3, 2005
    #2
    1. Advertising

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

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Dani Isenegger, Jan 4, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Èý¹â
    Replies:
    1
    Views:
    578
    William F. Robertson, Jr.
    Jul 29, 2003
  2. Replies:
    0
    Views:
    5,141
  3. Mikko Nummelin

    XSLT namespace question

    Mikko Nummelin, Nov 20, 2003, in forum: XML
    Replies:
    6
    Views:
    431
    Chris Lovett
    Nov 22, 2003
  4. Anonymous
    Replies:
    3
    Views:
    535
    Ron Natalie
    Aug 18, 2003
  5. Replies:
    18
    Views:
    2,768
    Joseph Kesselman
    Oct 4, 2006
Loading...

Share This Page