0

I have my string as below

<Text>Pack:NA Lead:20 Dimension:235</Text>

And need to map

NA to outputfield1
20 to outputfield2
235 to outputfield3

How to do this correctly in xslt mapping where the values 'NA,20,235' could be different each time?

I could only see substring component which takes length as second parameter. That leads requires several steps to achieve this.

Any better solution to just take the value between Lead: and Dimension for outputfield2?

mickmackusa
  • 43,625
  • 12
  • 83
  • 136
Dev
  • 57
  • 1
  • 7
  • Which version of XSLT are you using? If you have tried any code, please share it? Also are the output values going to be values associated with `Pack:`, `Lead:` and `Dimension:` or these too change? – Aniket V Oct 16 '17 at 05:58
  • xsl:stylesheet version="1.0" , – Dev Oct 16 '17 at 06:06
  • yes always the input have Pack:, Lead: and Dimension:[only the values may change] – Dev Oct 16 '17 at 06:07
  • If you are stuck with XSLT 1.0 as the only option then splitting the string for `space` character and then using `substring-after` would probably be the way to go. If you can use XSLT 2.0, then it has built in functions which will make this task easy. – Aniket V Oct 16 '17 at 06:26
  • how to split the string for space - any function to use that ? – Dev Oct 16 '17 at 06:42
  • There is no built-in function in XSLT 1.0. You need to write a recursive template to split the string. Here is a [reference](https://stackoverflow.com/questions/3336424/does-xslt-have-split-function) to start. – Aniket V Oct 16 '17 at 06:44

1 Answers1

0

To extract the Pack value, you can use:

<xsl:value-of select="substring-before(substring-after(Text, 'Pack:'), ' ')" />

To extract the Lead value, use:

<xsl:value-of select="substring-before(substring-after(Text, 'Lead:'), ' ')" />

To extract the Dimension:

<xsl:value-of select="substring-after(Text, 'Dimension:')" />
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51