 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

September 10th, 2010, 03:45 PM
|
|
Registered User
|
|
Join Date: Sep 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Parsing a string using XSLT
Hi all,
I have data in the format of:
AAAAAAAA*BBBBBBBBB^AAAAAAAA*BBBBBBBBB^AAAAAAAA*BBB BBBBBB^
Or more specifically a regular expression of:
(AAAAAAAA*BBBBBBBBB^) AAAAAAAA*BBBBBBBBB^
Where what is in parenthesis occurs 0 to many times. This string is coming across in an xml element and I need to transform it into this format:
<tag1>
<Field1> AAAAAAAA </Field1>
<Field2> BBBBBBBBB </Field2>
</tag1>
<tag1>
<Field1> AAAAAAAA </Field1>
<Field2> BBBBBBBBB </Field2>
</tag1>
<tag1>
<Field1> AAAAAAAA </Field1>
<Field2> BBBBBBBBB </Field2>
</tag1>
I have to use XSLT, because this is going into a biztalk solution and I canât change the schemas. I think i can create the xml using xslt, but i don't know how to parse the strings with it. Any ideas?
Thanks,
Brian
|
|

September 10th, 2010, 04:08 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
This is very easy using XSLT 2.0's xsl:analyze-string construct, but unfortunately if you're in Biztalk then I imagine you're stuck with XSLT 1.0, which has very limited string-handling capability, and in particular, no regular expression support.
However, it can be done without too much difficulty using a recursive named template. Write a template that accepts a parameter S (your input string) and uses substring-before() to extract the first two components of S and output the corresponding elements; then use substring-after() to extract the remainder of S, and call the template recursively passing this as the value of S to be processed in the same way, terminating the recursion when the string S is empty.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

September 13th, 2010, 09:11 AM
|
|
Registered User
|
|
Join Date: Sep 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
mhkay-
I will look into the recursive named template idea, but as I am new to XSLT, I had an idea this morning to use a vb.net or C# script instead. Doesn't the XSLT script in a BizTalk functoid just return a string that is XML? If so, can I not build a string using any other scripting language? My BT output template is an EDI 214 which has the following heirarchy:
L11 - higher level
L1101 - the AAAAA field I want to fill.
L1102 - the BBBBB field I want to fill.
Can't I just build the XML string and move to L11? Well unless something else was wrong(and i don't think so because the code worked in a test project), moving the output XML string to L11 generated a "The element L11 has an invalid structure" error.
Brian
|
|

September 13th, 2010, 09:51 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
If you're learning a new language it's very tempting to drop back into a familiar language as soon as the going gets tough. In the long run, though, all this does is to increase the elapsed time before you become proficient in the new technology.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

September 13th, 2010, 10:21 AM
|
|
Registered User
|
|
Join Date: Sep 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I only started learning the language on Friday because I was told I had to. Right now I have a task to complete at work, not a ton of time to become proficient with a language that i've only seen for a few days. I was just wondering if it was possible then when I have more time, go back and learn the new language properly. I agree with you that it does take time, unfortunately, I just don't have a lot of it at the moment.
thanks,
Brian
|
|

September 13th, 2010, 11:03 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
It is probably very likely give that the XSLT processor in Biztalk is probably the microsoft XSLT processor that you can write extension scripts in C# or perhaps javascript (depending on many things like such as which version of Biztalk you are using and how the processor is initialised).
Try a google for "extension functions xslt c#". or "extension functions msxml javascript"
As a XSLT forum we are probably better equipped to answer the original question in pure XSLT.
|
|

September 13th, 2010, 11:10 AM
|
|
Registered User
|
|
Join Date: Sep 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I really appreciate yours and mhkay's comments. I originally posted here because I was told the only way to do it was in XSLT. If it is, then I do need help because even his suggestion on how he would approach the problem is above my ability to understand it. I am on about chapter 7 or so of the XSLT for dummies book. I need to understand that before I can graduate to a more powerful book such as the one he has written. I actually have his book in front of me(the programmer's reference 2nd anyway). Unfortunately for me, this book is written for someone who has a lot more experience with the language than I currently have. I was hoping for some help from those who had some time. Right now, I can do not much more than this type of stuff:
<xsl: template name="MyName">
<xsl:param name = "L11"/>
<xsl:param name = "L1101"/>
<xsl:param name = "L1102"/>
I am trying. Maybe you can answer this question. The output of an XSLT file is just XML text right? If so, is that still true of the output string when using a BizTalk functoid? I should be able to send that output to the <L11> right?(See previous post). I really appreciate your time in answering these things.
Thanks,
Brian
|
|

September 13th, 2010, 11:48 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
I don't recognise the phrase "functiod" so I don't know what it returns.
In C# XSLT extension functions you either return a node set or a string.
Extension functions can usually be called in any xpath expression, e.g.
<xsl:value-of select="biz:myfunctions('X')"/>
|
|
 |