xsl-list
[Top] [All Lists]

RE: passing_cousin_content_as_counter

2004-08-02 07:26:56

Hallo Mr Kay,

A little matter of protocol. I reply to requests for free help only if (a) I
find the question interesting, and (b) I have time to answer it. You are
therefore very likely to get no answer. If you say the question is urgent, I
am more likely to ignore it, since I don't like being on anyone's critical
path. If you direct the question to one person in particular, it is likely
to be ignored by everyone else. So you are not choosing an optimum strategy
for getting your question answered.

The source xml is the one following, slightly diferrent from 
the one i sent
you yesterday(it
just includes and a second SHAPE element).

<?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>
                  <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>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>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>


I am using the following stylesheet to select all 
ORDINATE_ITEM contents in
a string
as the content of a new polygon element of the output xml.



<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() mod 2 = 1">
                                    <xsl:value-of
select="format-number(.,'#')"/>
                                    <xsl:text>,</xsl:text>
                              </xsl:when>
                              <xsl:when test="position() mod 2 = 0">
                                    <xsl:value-of
select="format-number(.,'#')"/>
                                    <xsl:text> </xsl:text>
                              </xsl:when>
                        </xsl:choose>
                  </xsl:for-each>
            </polygon>
            </PolygonSet>
      </xsl:template>
</xsl:stylesheet>


This results to an xml output like the one following:

<?xml version="1.0" encoding="UTF-8"?>
<PolygonSet>
   <polygon>483640,4314481 483653,4314497 483697,4314548 
483640,4314481
</polygon>
   <polygon>483168,4314455 483171,4314466 483184,4314517 
483203,4314600
483205,4314605 483168,4314455 483199,4314726 483199,4314729 
483193,4314853
483199,4314726 </polygon>
</PolygonSet>

If now i also want to make use of the code you sent me in 
order to mark
ORDINATE_ITEM element's
content whose position is specified like :
position() =
     /ROWSET/ROW/SHAPE/ELEM_INFO/ELEM_INFO_ITEM[position() mod 3 = 1]
by adding a d infront of them, can it be achieved through this same
stylesheet?



I tried adding another <xsl:when statement  to the when 
node-set of the
previous stylesheet like

<xsl:when test="position() =
/ROWSET/ROW/SHAPE/ELEM_INFO/ELEM_INFO_ITEM[position() mod 3 = 1]>
<xsl:text>d</xsl:text><xsl:value-of select="."/>
</xsl:when>

or

<xsl:when test="position() =
/ROWSET/ROW/SHAPE/ELEM_INFO/ELEM_INFO_ITEM[position() mod 3 = 1]>
<xsl:value-of select="concat('d',.)"/>
</xsl:when>

but it didn't work.

If you've simply added this xsl:when clause after the existing xsl:when
clauses then it will have no effect because only the first xsl:when whose
condition is satisfied will be activated.

I also tried adding a second template to the previous stylesheet like:

<xsl:template match="SDO_ORDINATES_ITEM[position() =
     
/ROWSET/ROW/SHAPE/SDO_ELEM_INFO/SDO_ELEM_INFO_ITEM[position() mod 3 =
1]]">
            <xsl:copy>
                  <xsl:text>d</xsl:text>
                  <xsl:value-of select="."/>
            </xsl:copy>
      </xsl:template>
but it was also ignored.


There is no xsl:apply-templates in the previous stylesheet, so adding
another template rule will have no effect. 

Do you think that i will definitely have to use a second stylesheet in
order to obtain
this output, or can it also be managed through the same stylesheet?


No, there is no need for a second stylesheet. You just need to think more
clearly about the logic.

Michael Kay