I use xslt to substring before:
<xsl:element name="mapcat">
<xsl:value-of select="substring-before(categories,'/')"/>
</xsl:element>
Original:
17845/288323/8844
Result:
17845
Working correct
Now I need substring after 10 characters.
I try:
<xsl:element name="mapcat">
<xsl:value-of select="substring(categories,'1,10')"/>
</xsl:element>
But something went wrong and no working. Can anyone help me correct this code?
I need substring after 10 characters.
I am guessing you want to do:
<xsl:value-of select="substring(original-string, 11)"/>
Your explanation of the problem wasn't very clear (difficulties with your English perhaps?) but from the example supplied as a comment you want the first 11 characters of the string, which is substring(xx, 1, 11). Supplying 0 (or anything less than 1) as the second argument has the same effect: the actual semantics of substring(x, a, b) are to include all characters in x whose position p (counting from 1) satisfies p>=a and p<(a+b) -- with additional rules for rounding if the values are not integers.
Related
Could you please help how to add or sub integer from substring? Here below my substring, and want to add this value to 5
<xsl:value-of select="substring($values/smt1/smt2[position()=1]/smt3 , 12, 2)"/>
Lets say above value is 3, how to make it 8? And can i use also mod opetator?
Thanks
If $string contains "abc03de", then:
<xsl:value-of select="substring($string, 4, 2)"/>
returns "03".
In XSLT 1.0 you can do:
<xsl:value-of select="substring($string, 4, 2) + 5"/>
to get a result of 8.
In XSLT 2.0+ you need to expressly convert the resulting substring to a number before it can be used in a numerical operation, e.g.:
<xsl:value-of select="number(substring($string, 4, 2)) + 5"/>
current Output
<wd:GradeCode>CH_Service_Fly_test worker</wd:GradeCode>
<wd:GradeCode>CN_Dips_12 Engineer depart</wd:GradeCode>
Output needed
<wd:GradeCode>Service_Fl</wd:GradeCode>
<wd:GradeCode>Dips_12 En</wd:GradeCode>
Unfortunately little input. Which could probably work, would be the following function (depending on what you have in mind):
<!-- build a string after the first underline -->
<xsl:variable name="firstString">
<xsl:value-of select="substring-after(., '_')"/>
</xsl:variable>
<!-- limit the firstString to 10 digits -->
<xsl:value-of select="substring($firstString/text(),1,10)"/>
The pending to use for each item.
Is there a way to substring my value 6 places after decimal?
So if I have
<xsl:value-of select="100.1234567890" />
Is there a way to make it
"100.123456"
Your value is a number, not a string. The easy way to trim it to 6 decimal places is to floor it, not substring it:
<xsl:value-of select="floor(100.1234567890 * 1000000) div 1000000"/>
returns:
100.123456
To achieve the same thing through string manipulation, you could do:
<xsl:variable name="n" select="'100.1234567890'" />
<xsl:value-of select="substring($n, 1, string-length(substring-before($n, '.')) + 7)"/>
here is my current xslt:
<xsl:when test="position()=10">
This works, but i have 100 records so it only produces my neccessary html on the 10th record, and nothing more.
what i need now is a dynamic way of saying when is every ten positions. i imagine you could use modulus but im having difficulty getting that to work.
Ive tried:
<xsl:when test="position() mod 10">
Not sure what the solution is.
I think you want <xsl:when test="position() mod 10 = 0">.
My request is as below . The EmpNumberList will have 250 EmpNumbers separated by space.
<soapenv:Body>
<v1:MRRequestParam>
<v1:EmpNumberList><v1:EmpNumber> 9989071005 2004421004</v1:EmpNumber></v1:EmpNumberList>
</v1:MRRequestParam>
</soapenv:Body>
The XSLT I need to write should count the EmpNumbers from the EmpNumbersList
I need to call stored procedure in my XSLT such that i make 5 calls .
In one call I pass only 50 EmpNumbers.
I make 5 calls in total
First Call will have $EmpNumber1 such that it contains 50 EmpNumbers
$EmpNumber1 = 9989071005 2004421004 (so on 50 EmpNumbers)
<argument type="SQL_VARCHAR" mode="INPUT" nullable="true" precision="0" scale="0" isNull="false"><xsl:value-of select="$EmpNumber1" />
</argument>
When I send back the response I need to club all 5 result set and send at a time.
Please let me know if you have any suggestions
This one is easy:
Use:
string-length(translate(normalize-space(/*/*/*/v1:EmpNumber), '0123456789',''))+1
When applied on this document (the provided one with one more number):
<soapenv:Body xmlns:soapenv="my:soapenv">
<v1:MRRequestParam xmlns:v1="my:v1">
<v1:EmpNumberList>
<v1:EmpNumber> 9989071005 2004421004 1234567890 </v1:EmpNumber>
</v1:EmpNumberList>
</v1:MRRequestParam>
</soapenv:Body>
the wanted, correct result is returned:
3
Here is a complete XSLT 1.0 stylesheet to run and verify that the correct results are always produced:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soapenv="my:soapenv" xmlns:v1="my:v1">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of select=
"string-length(
translate(normalize-space(/*/*/*/v1:EmpNumber), '0123456789','')
)+1"/>
</xsl:template>
</xsl:stylesheet>
Do note: You have to specify the correct namespaces in the transformation and in the XML document -- you haven't provided them in your question.
Explanation:
The meaning of this expression:
string-length(
translate(normalize-space(/*/*/*/v1:EmpNumber), '0123456789','')
)+1
is:
normalize-space() . This takes the string and produces a new string from it, in which all leading and trailing whitespace characters are deleted.
What remains are only the numbers with just one intermediate space character between every two numbers. So, if there are N numbers, the number of spaces is N-1.
The translate() function as referenced in the expression, returns a new string in which all digits are gone (replaced by the empty string ''. What remains are only the space characters.
Using the string-length() function we simply get the count of those spaces** (N-1). We add 1 and get the number N of all the numbers in the string.