Reputation: 93
I'm trying to extract the 2 first digits from a number.
I have this XML:
<extraccio data="01-05-2013" tipus_objecte="5">
<objRegistral>
<categoria id="69">2A. CATEGORIA</categoria>
<cadastral/>
<web>www.campingelcarlitos.com</web>
<email>[email protected]</email>
<adreca>
<no_normalitzada>Cra. N-II, km 658,7</no_normalitzada>
<tipus_via id="28">Ctra</tipus_via>
<nom_via>N-II</nom_via>
<num>km 658,7</num>
<bloc/>
<escala/>
<pis/>
<porta/>
**<cp>08350</cp>**
<municipi id="893">Arenys de Mar</municipi>
<inframunicipi/>
<comarca id="21">Maresme</comarca>
<provincia id="8">BARCELONA</provincia>
<comunitat/>
<marca_turistica>COSTA DE BARCELONA-MARESME</marca_turistica>
<utm_x>464187</utm_x>
<utm_y>4603963</utm_y>
<utm_z/>
</adreca>
.......
I need to extract the 2 first digits from the tag <cp>..</cp>
I have this code XSLT:
The error is that i cant compare string to integer
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="/">
<campings>
<xsl:for-each select="extraccio/objRegistral/dades_generals/adreca[substring(cp,2)= 08]">
<camping>
<nom><xsl:value-of select="municipi"/></nom>
</camping>
</xsl:for-each>
</campings>
</xsl:template>
</xsl:stylesheet>
Upvotes: 1
Views: 383
Reputation: 86774
In
<xsl:for-each select="extraccio/objRegistral/dades_generals/adreca[substring(cp,2)= 08]">
you need to express the value you are looking for as a string
...[starts-with(cp,'08')]
Upvotes: 2