XSLT Question
March 16, 2010 2:34 PM   Subscribe

In XSLT, if I know that the entries in a certain field will always be of the form "ABC_1234blahblahblah", is there a way to get just "ABC_1234"? There will always be three letters, an underscore and four numerals, but the specific letters and numbers change from file to file, as does the length and content of the junk after the numbers. I don't actually know XSLT at all, I'm just trying to make a quick fix to some code written by someone else.
posted by Awkward Philip to Computers & Internet (5 answers total)
Ok, so I know this might seem kind of heretical, but (since we're in the land of quick fixes anyway) would you consider extracting the relevant information with a regex instead?
posted by Jpfed at 2:48 PM on March 16, 2010

If they've just got a simple [xsl:value-of select='field'/] you can change that to grab a substring out using e.g. [xsl:value-of select='substring(field,1,8)'/] to get the first 8 characters.
mefi ate my <!
posted by samj at 2:55 PM on March 16, 2010

Yeah, substring(). A simple tutorial.
posted by and hosted from Uranus at 2:59 PM on March 16, 2010

Sounds like samj's got the answer. FYI, you can type angle brackets if you escape the characters (type "&lt;" for "<" and "&gt;" for ">"). Thus:

<xsl:value-of select='substring(field,1,8)' />
posted by The Winsome Parker Lewis at 3:00 PM on March 16, 2010

That's what I was looking for. Thanks!
posted by Awkward Philip at 3:00 PM on March 16, 2010

« Older Need London music scene   |   What are these orange and green decorated shops in... Newer »
This thread is closed to new comments.