Subject: [xsl] SelectingSubsetsOfNode-SetsByPositionIntervals From: mankar@xxxxxxxxxxxxxxx Date: Fri, 6 Aug 2004 17:24:07 +0300 |
Hallo, after getting a lot of help from the xsl-list it became possible for this xml source doc: <?xml version="1.0" encoding="ISO-8859-7"?> <ROWSET> <ROW num="1"> <SHAPE> <ELEM_INFO> <ELEM_INFO_ITEM>1</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>1003</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>1</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>6</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>1003</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>1</ELEM_INFO_ITEM> </ELEM_INFO> <ORDINATES> <ORDINATES_ITEM>483639.599589384</ORDINATES_ITEM> <ORDINATES_ITEM>4314480.8582032</ORDINATES_ITEM> <ORDINATES_ITEM>483653.418277397</ORDINATES_ITEM> <ORDINATES_ITEM>4314497.09551522</ORDINATES_ITEM> <ORDINATES_ITEM>483696.866709438</ORDINATES_ITEM> <ORDINATES_ITEM>4314548.14836326</ORDINATES_ITEM> <ORDINATES_ITEM>483639.599589384</ORDINATES_ITEM> <ORDINATES_ITEM>4314480.8582032</ORDINATES_ITEM> </ORDINATES> </SHAPE> </ROW> <ROW num="2"> <SHAPE> <ELEM_INFO> <ELEM_INFO_ITEM>1</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>1003</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>1</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>5</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>2003</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>1</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>13</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>2003</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>1</ELEM_INFO_ITEM> </ELEM_INFO> <ORDINATES> <ORDINATES_ITEM>483168.460580946</ORDINATES_ITEM> <ORDINATES_ITEM>4314454.74669918</ORDINATES_ITEM> <ORDINATES_ITEM>483171.116692948</ORDINATES_ITEM> <ORDINATES_ITEM>4314465.79279519</ORDINATES_ITEM> <ORDINATES_ITEM>483183.52147696</ORDINATES_ITEM> <ORDINATES_ITEM>4314517.37383524</ORDINATES_ITEM> <ORDINATES_ITEM>483203.420852978</ORDINATES_ITEM> <ORDINATES_ITEM>4314600.12101931</ORDINATES_ITEM> <ORDINATES_ITEM>483204.637028979</ORDINATES_ITEM> <ORDINATES_ITEM>4314605.17829932</ORDINATES_ITEM> <ORDINATES_ITEM>483168.460580946</ORDINATES_ITEM> <ORDINATES_ITEM>4314454.74669918</ORDINATES_ITEM> <ORDINATES_ITEM>483198.743348974</ORDINATES_ITEM> <ORDINATES_ITEM>4314725.56217143</ORDINATES_ITEM> <ORDINATES_ITEM>483198.594772974</ORDINATES_ITEM> <ORDINATES_ITEM>4314728.70069943</ORDINATES_ITEM> <ORDINATES_ITEM>483192.709572968</ORDINATES_ITEM> <ORDINATES_ITEM>4314852.93913155</ORDINATES_ITEM> <ORDINATES_ITEM>483198.743348974</ORDINATES_ITEM> <ORDINATES_ITEM>4314725.56217143</ORDINATES_ITEM> </ORDINATES> </SHAPE> </ROW> </ROWSET> to be transformed with the use of the following stylesheet: <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output indent="yes"/> <xsl:template match="/"> <PolygonSet> <xsl:for-each select="ROWSET/ROW"> <polygon> <xsl:for-each select="SHAPE/ORDINATES/ORDINATES_ITEM"> <xsl:choose> <xsl:when test="position() = ancestor::SHAPE/ELEM_INFO/ELEM_INFO_ITEM[position() mod 3=1]"> <xsl:value-of select="concat('M',.)"/> <xsl:text> </xsl:text> </xsl:when> <xsl:otherwise> <xsl:value-of select="."/> <xsl:text> </xsl:text> </xsl:otherwise> </xsl:choose> </xsl:for-each> </polygon> </xsl:for-each> </PolygonSet> </xsl:template> </xsl:stylesheet> into the following xml output: <?xml version="1.0" encoding="UTF-8"?> <PolygonSet> <polygon>M483639.599589384 4314480.8582032 483653.418277397 4314497.09551522 483696.866709438 M4314548.14836326 483639.599589384 4314480.8582032 </polygon> <polygon>M483168.460580946 4314454.74669918 483171.116692948 4314465.79279519 483183.52147696 4314517.37383524 483203.420852978 4314600.12101931 483204.637028979 4314605.17829932 483168.460580946 4314454.74669918 M483198.743348974 4314725.56217143 483198.594772974 4314728.70069943 483192.709572968 4314852.93913155 483198.743348974 4314725.56217143 </polygon> <polygon>M483168.460580946 4314454.74669918 M483171.116692948 4314465.79279519 483183.52147696 4314517.37383524 483203.420852978 4314600.12101931 483204.637028979 4314605.17829932 483168.460580946 4314454.74669918 483198.743348974 4314725.56217143 483198.594772974 4314728.70069943 483192.709572968 4314852.93913155 483198.743348974 4314725.56217143 </polygon> </PolygonSet> which selects all ORDINATE_ITEM elements of each ROW/SHAPE as string content of a polygon element,adding an M character at the same time to the content of ORDINATE_ITEM elements whose position is denoted by the ELEM_INFO_ITEM[position()mod 3=1] content for each ROW/SHAPE. I was wondering if it is also possible to select subsets of the ORDINATE_ITEM node-set of each SHAPE by using these positions declared by ELEM_INFO_ITEM[position()mod 3=1].I mean for example, for the fisrt ROW/SHAPE of the source XML, using this XPath syntax i get to select ORDINATE_ITEM elements whose position is 1 and 6. <ROW num="1"> <SHAPE> <ELEM_INFO> <ELEM_INFO_ITEM>1</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>1003</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>1</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>6</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>1003</ELEM_INFO_ITEM> <ELEM_INFO_ITEM>1</ELEM_INFO_ITEM> </ELEM_INFO> <ORDINATES> <ORDINATES_ITEM>483639.599589384</ORDINATES_ITEM> 1st position <ORDINATES_ITEM>4314480.8582032</ORDINATES_ITEM> <ORDINATES_ITEM>483653.418277397</ORDINATES_ITEM> <ORDINATES_ITEM>4314497.09551522</ORDINATES_ITEM> <ORDINATES_ITEM>483696.866709438</ORDINATES_ITEM> <ORDINATES_ITEM>4314548.14836326</ORDINATES_ITEM> 6th position <ORDINATES_ITEM>483639.599589384</ORDINATES_ITEM> <ORDINATES_ITEM>4314480.8582032</ORDINATES_ITEM> Can i also use this XPath syntax to define position intervals (1-5) and (6-last) and select all ORDINATE_ITEM elemets between these positions into diferrent node-sets.To be more specific can i select all ORDINATE_ITEM elements from position 1 to position 5 and then all all ORDINATE_ITEM elements from position 6 to the last position? Thanks Regards Manousos Athens
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Preserve HTML formatting , Passin, Tom | Thread | Re: [xsl] SelectingSubsetsOfNode-Se, David Carlisle |
Re: [xsl] Parametrized includes -wo, Ralph Holz | Date | Re: [xsl] Linenumbering & word inde, David Carlisle |
Month |