Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Preceding with partial string

From: rnakawat@-----.---
To: NULL
Date: 6/5/2008 11:12:00 PM
I seem to have a problem using the preceding:: on substrings of the
value.  I'll try to explain with an example:

Let's say I had a XML that look like:

<Root>
    <Row>
        <Cell Name="Street" Value="2nd Street" />
    </Row>
     <Row>
        <Cell Name="Street" Value="Meadow Lane" />
    </Row>
    <Row>
        <Cell Name="Street" Value="2nd Street" />
    </Row>
   <Row>
        <Cell Name="Street" Value="2nd Street" />
    </Row>
    <Row>
        <Cell Name="Street" Value="Meadow Lane" />
    </Row>

</Root>

Let's say I want to find the distinct streets.  This is straight
forward and may look something like:


<xsl:template match="Root">
	<xsl:element name="root">


		<xsl:for-each select="./Row[Cell[@Name = 'Street' and not(@Value =
preceding::Cell[@Name= 'Street']/@Value) ]]">

			<xsl:variable name="UniqueStreet" select="./Cell[@Name='Street']/
@Value"/>

			<xsl:element name="street">
				<xsl:attribute name="name">
					<xsl:value-of select="$UniqueStreet"/>
				</xsl:attribute>

				<!-- This is where I would reiterate through the list to get the
list of residents
						that live on that block -->
			</xsl:element>
		</xsl:for-each>
	</xsl:element>
</xsl:template>

This returns what I expect:

<root>
  <street name="2nd Street"/>
  <street name="Meadow Lane"/>
</root>

But let's say the address contained street numbers, and I needed to
strip out the street numbers when trying to look for unique street
names.


<Root>
    <Row>
        <Cell Name="Address" Value="1345 2nd Street" />
    </Row>
    <Row>
        <Cell Name="Address" Value="332 Meadow Lane" />
    </Row>
	<Row>
        <Cell Name="Address" Value="333 2nd Street" />
    </Row>
	<Row>
        <Cell Name="Address" Value="8534 2nd Street" />
    </Row>
	   <Row>
        <Cell Name="Address" Value="556 Meadow Lane" />
    </Row>

</Root>

	<xsl:template match="Root">
		<xsl:element name="root">


				<xsl:for-each select="./Row[Cell[@Name = 'Address' and
not(substring-after(@Value, ' ') = substring-
after(preceding::Cell[@Name= 'Address']/@Value, ' ')) ]]">

					<xsl:variable name="UniqueStreet" select="substring-after(./
Cell[@Name='Address']/@Value, ' ')"/>

					<xsl:element name="street">
						<xsl:attribute name="name"><xsl:value-of select="$UniqueStreet"/
></xsl:attribute>

						<!-- This is where I would reiterate through the list to get the
list of residents
							that live on that block -->
					</xsl:element>
				</xsl:for-each>
		</xsl:element>
	</xsl:template>

This yields the output:

<root>
  <street name="2nd Street"/>
  <street name="Meadow Lane"/>
  <street name="Meadow Lane"/>
</root>

Can someone explain why that is happening and how I can fix it?


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent