I have a complex adress string, or rather different possible formats, which I need to split into road name, house number, floor, position (left,right,middel door) or door/room number
I have managed to do all apart from the last bit, with the pseudo “contains”:
<xsl:choose>
<xsl:when test="contains(@addressFarLeft, ANY_NUMERIC_VALUE_ANYWHERE)">
<door>NUMERICVALUE</door>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
Im pretty sure I cant just use some form of contains, but what then?
Value is set dynamically, but here are a few possible values:
<xsl:variable name="addressFarLeftValue">.th.</xsl:variable> =>
no numeric value, do nothing
<xsl:variable name="addressFarLeftValue">.1.</xsl:variable> =>
produce: <door>1</door>
<xsl:variable name="addressFarLeftValue">, . tv </xsl:variable> =>
no numeric value, do nothing
<xsl:variable name="addressFarLeftValue">,th, 4.</xsl:variable> =>
produce: <door>1</door>
Any suggestions?
If you want to test whether a string contains a numeric value, one approach could be to use the ‘translate’ function to remove all numeric digits from the string, and if the resultant string doesn’t match the initial string, you know it must have contained a number. If the string doesn’t change, then it didn’t.
So,
<xsl:variable name="addressFarLeftValue">.1.</xsl:variable>outputs<door>1</door>, but<xsl:variable name="addressFarLeftValue">.th.</xsl:variable>doesn’t output anything.IF you wanted to extract the actual number, then assuming there was only one occurence of a number in the string, you could do this…
So,
<xsl:variable name="addressFarLeftValue">,th, 42.</xsl:variable>outputs 42If you had multiple numbers present, such as
,th, 42, ab, 1this approach would fail though.