Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSLT schema translation problem

Status
Not open for further replies.

sedj

Programmer
Aug 6, 2002
5,610
Hi,

For the life of me, I cannot work out how to transform the below xml to the xml below that. I realize it would be easier if the POLYGGON_LIST were split into their respective two POLYGON elements, but unfortunately I cannot change the source schema. Any hint as to how I can do this in XSLT would be appreciated !

Below is the input source, and below that is the desired output. Thanks for any help with this !!!

Code:
<NUMBER_OF_POLYGONS>2</NUMBER_OF_POLYGONS>
<POLYGON_LIST>
	<POLYGON_TYPE>H</POLYGON_TYPE>
	<NUMBER_OF_COORDINATES>4</NUMBER_OF_COORDINATES>
	<POINT>
		<EASTING>some coordX</EASTING>
		<NORTHING>some coordY</NORTHING>
	</POINT>
	<POINT>
		<EASTING>some coordX</EASTING>
		<NORTHING>some coordY</NORTHING>
	</POINT>
	<POINT>
		<EASTING>some coordX</EASTING>
		<NORTHING>some coordY</NORTHING>
	</POINT>
	<POINT>
		<EASTING>some coordX</EASTING>
		<NORTHING>some coordY</NORTHING>
	</POINT>
	<POLYGON_TYPE>H2</POLYGON_TYPE>
	<NUMBER_OF_COORDINATES>4</NUMBER_OF_COORDINATES>
	<POINT>
		<EASTING>some coordX</EASTING>
		<NORTHING>some coordY</NORTHING>
	</POINT>
	<POINT>
		<EASTING>some coordX</EASTING>
		<NORTHING>some coordY</NORTHING>
	</POINT>
	<POINT>
		<EASTING>some coordX</EASTING>
		<NORTHING>some coordY</NORTHING>
	</POINT>
	<POINT>
		<EASTING>some coordX</EASTING>
		<NORTHING>some coordY</NORTHING>
	</POINT>
</POLYGON_LIST>

Code:
<gml:Polygon srsName="BNG">
	<gml:outerBoundaryIs>
	<gml:LinearRing>
	<gml:coord>
		<gml:X>some coordX</gml:X>
		<gml:Y>some coordY</gml:Y>
	</gml:coord>
	<gml:coord>
		<gml:X>some coordX</gml:X>
		<gml:Y>some coordY</gml:Y>
	</gml:coord>
	<gml:coord>
		<gml:X>some coordX</gml:X>
		<gml:Y>some coordY</gml:Y>
	</gml:coord>
	<gml:coord>
		<gml:X>some coordX</gml:X>
		<gml:Y>some coordY</gml:Y>
	</gml:coord>
	</gml:LinearRing>
	</gml:outerBoundaryIs>
</gml:Polygon>
<gml:Polygon srsName="BNG">
	<gml:outerBoundaryIs>
	<gml:LinearRing>
	<gml:coord>
		<gml:X>some coordX</gml:X>
		<gml:Y>some coordY</gml:Y>
	</gml:coord>
	<gml:coord>
		<gml:X>some coordX</gml:X>
		<gml:Y>some coordY</gml:Y>
	</gml:coord>
	<gml:coord>
		<gml:X>some coordX</gml:X>
		<gml:Y>some coordY</gml:Y>
	</gml:coord>
	<gml:coord>
		<gml:X>some coordX</gml:X>
		<gml:Y>some coordY</gml:Y>
	</gml:coord>
	</gml:LinearRing>
	</gml:outerBoundaryIs>
</gml:Polygon>

--------------------------------------------------
Free Database Connection Pooling Software
 
Got it (albeit in a hack manner) :

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:gml="[URL unfurl="true"]http://www.opengis.net/gml"[/URL]  xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]
	<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes"/>
	
	<xsl:template match="/"><xsl:apply-templates/></xsl:template>

	<xsl:template match="NUMBER_OF_COORDINATES"/>
	
	<xsl:template match="NUMBER_OF_POLYGONS"/>
	
	<xsl:template match="POLYGON_LIST">
	
		<gml:Polygon srsName="BNG">
		    <gml:outerBoundaryIs>
		    <gml:LinearRing>

			<xsl:apply-templates/>
			
		    </gml:LinearRing>
		    </gml:outerBoundaryIs>
		</gml:Polygon>
		
	</xsl:template>



	<xsl:template match="POINT">
    <gml:coord>
        <gml:X><xsl:value-of select="EASTING"/></gml:X>
        <gml:Y><xsl:value-of select="NORTHING"/></gml:Y>
    </gml:coord>	
		
	</xsl:template>	
		
	<xsl:template match="POLYGON_TYPE">
		<xsl:variable name="num" select="//NUMBER_OF_POLYGONS"/>
		<xsl:choose>
			<xsl:when test="$num != 1">		
				<xsl:choose>
					<xsl:when test="position() > $num">
					<xsl:text disable-output-escaping="yes">
						    &lt;/gml:LinearRing&gt;
						    &lt;/gml:outerBoundaryIs&gt;
						&lt;/gml:Polygon&gt;


						&lt;gml:Polygon srsName="BNG"&gt;
						    &lt;gml:outerBoundaryIs&gt;
						    &lt;gml:LinearRing&gt;
					</xsl:text>
					
					</xsl:when>
					
				</xsl:choose>
			</xsl:when>
		</xsl:choose>			
	</xsl:template>	
</xsl:stylesheet>

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top