tesmc
asked on
XSL: obtain last word in a text
I have the following XML
<ServInfo CMD="011">
<Serv Code="ED" Type="RED">
<Text>AS KK1 06L18MAR/CHAIR/ACCPT/USD20 00/100RC CCVIXXXXXXXXXXXX0001EXPXXX X 8312312270746</Text>
</Serv>
I want to obtain the the last field in <text> = 8312312270746. I have following but I don't think I"m referencing the @CMD correctly bc it errors out.
<xsl:variable name="test" select ="//Itin/ServInfo[Serv[@Co de='ED' and @Type = 'RED']/@CMD=$id/Text " />
where $id = 11
<ServInfo CMD="011">
<Serv Code="ED" Type="RED">
<Text>AS KK1 06L18MAR/CHAIR/ACCPT/USD20
</Serv>
I want to obtain the the last field in <text> = 8312312270746. I have following but I don't think I"m referencing the @CMD correctly bc it errors out.
<xsl:variable name="test" select ="//Itin/ServInfo[Serv[@Co
where $id = 11
for getting the last component in XSLT2
<xsl:value-of select="tokenize(normalize -space($te st), ' ')[last()]"/>
in XSLT1 you will need to use recursion
<xsl:value-of select="tokenize(normalize
in XSLT1 you will need to use recursion
ASKER
i used XSLT1.
<xsl:variable name="test" select ="//Itin/ServInfo[Serv[@Co de='ED' and @Type = 'RED']][number(@CMD) = number($id)]/Text " />
and the Text wasn't found.
<xsl:variable name="test" select ="//Itin/ServInfo[Serv[@Co
and the Text wasn't found.
ASKER
XML input:
<ServInfo CMD="011">
<Serv Code="ED" Type="RED">
<Text>AS KK1 06L18MAR/CHAIR/ACCPT/USD20 00/100RC CCVIXXXXXXXXXXXX0001EXPXXX X 8312312270746</Text>
</Serv>
</ServInfo>
If I do
<xsl:variable name="test" select ="//Itin/ServInfo[Serv[@Co de='ED' and @Type = 'RED']]/Serv/Text " />
I can obtain all instances of Text where condition is satisfied.
But once i add the filter of the @CMD, nothing is found.
<xsl:variable name="test" select ="//Itin/ServInfo[Serv[@Co de='ED' and @Type = 'RED']][number(@CMD) = number($id)]/Text " />
<ServInfo CMD="011">
<Serv Code="ED" Type="RED">
<Text>AS KK1 06L18MAR/CHAIR/ACCPT/USD20
</Serv>
</ServInfo>
If I do
<xsl:variable name="test" select ="//Itin/ServInfo[Serv[@Co
I can obtain all instances of Text where condition is satisfied.
But once i add the filter of the @CMD, nothing is found.
<xsl:variable name="test" select ="//Itin/ServInfo[Serv[@Co
ASKER
nvmd, i got it to work with
<xsl:variable name="test" select ="//Itin/ServInfo[Serv[@Co de='ED' and @Type = 'RED']][number(@CMD) = number($id)]/Serv/Text " />
but now i just need to obtain the last string of that text node =8312312270746
<xsl:variable name="test" select ="//Itin/ServInfo[Serv[@Co
but now i just need to obtain the last string of that text node =8312312270746
Text is not a child of ServInfo, you need a Serv in between
<xsl:variable name="test" select ="//Itin/ServInfo[Serv[@Co de='ED' and @Type = 'RED']][number(@CMD) = number($id)]/Serv/Text " />
<xsl:variable name="test" select ="//Itin/ServInfo[Serv[@Co
Aha, you seem to have come to the same conclusion...
what is the logic for that last bit? Last 8 characters, numbers after the last space?
what is the logic for that last bit? Last 8 characters, numbers after the last space?
ASKER
The logic would be to obtain the value after the last space in text node.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks. it worked.
welcome
but I would force the attribute to a number to make sure it is numeric equality you get
<xsl:variable name="test" select ="//Itin/ServInfo[Serv[@Co