 |
| 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
|
|
|
|

April 19th, 2010, 11:51 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
I can try to adapt the XSLT 2.0 stylesheet to your real data but please repost it as with 19 replies so far in this thread I am not sure which one contains the real data.
The tokenize function in XSLT/XPath 2.0 takes a regular expression as its second argument and I already made that expression a global parameter in the stylesheet so you can easily set/adapt that to e.g. '[~,|]' to tokenize on any character given in the square brackets.
And if you don't want to process all child elements as the sample does that I posted then you simply need to make sure the function call to make-lines passes only those elements in you want or excludes some e.g. make-lines((), RecordSet/Data/* except (foo, bar)).
As for solving that with XSLT 1.0, that is much more effort as it does not have a tokenize function or regular expression support unless your XSLT processor supports some extension functions.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

April 19th, 2010, 12:02 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I guess, my process can't be changed. So XSLT 1 is the only way.
Here is ther real data with Tokenize fields only. But anywhere from top to bottom in between Tokenize fields, will be having regular fields as well. It will be written at the same positions, as present in the data while creating rows for us.
For tokenize items, some of the fields needs to be replaced with special chars. Example under <Audit_Auditees>
Auditee 1|Title 1
This needs to be output after tokenize as
Auditee 1{//}Title 1
Also as i am seeing no data outputting with earlier example, i like to cross check if the data present then only consider that tokenize fields etc...
Appreciate your prompt reply. Hope i am clear this time
HTML Code:
<?xml version="1.0" encoding="UTF-8"?>
<name>
<Recordset>
<Data>
<Audit_Auditees>Auditee 1|Title 1~Auditee 2|Title 2~Auditee 3|Title 3</Audit_Auditees>
<Audit_Auditors>~Auditor 1|Auditor Title 1</Audit_Auditors>
<Audit_Device>Device 1,Device 2,Device 3</Audit_Device>
<Audit_Lead_Auditor>Murray,Christopher|Murray,Christopher</Audit_Lead_Auditor>
<Audit_Sub_System>SubSystem1|Subsystem2|Subsystem3|Subsystem4</Audit_Sub_System>
<Audit_Sub_Type>SubType1|SubType2|</Audit_Sub_Type>
<Closing_Meeting_Attendees>Closing1~Closing2~Closing3</Closing_Meeting_Attendees>
<Closing_Meeting_Held_Date>2009-04-21T17:00:00Z</Closing_Meeting_Held_Date>
<MPG_Audit_Days>6</MPG_Audit_Days>
<MPG_Audit_Site>Abbott Park, IL</MPG_Audit_Site>
<MPG_Auditee_Organization>GPRD - Global Pharmaceutical R & D</MPG_Auditee_Organization>
<MPG_Auditing_Body>GPRD - Global Pharmaceutical R & D</MPG_Auditing_Body>
<MPG_Supplier_Capabilities>SupplierCapabilities</MPG_Supplier_Capabilities>
<Opening_Meeting_Attendees>Opening1~Opening2~Opening3</Opening_Meeting_Attendees>
</Data>
</Recordset>
</name>
|
|

April 19th, 2010, 01:01 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
If you need an XSLT 1.0 solution then I won't try to adapt my XSLT 2.0 stylesheet to your real data.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
|
|

April 19th, 2010, 01:20 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by Martin Honnen
If you need an XSLT 1.0 solution then I won't try to adapt my XSLT 2.0 stylesheet to your real data.
|
I can Understand. In that case, help me with the other issues i have with mhkay code, if possible. Appreciated
Nested Loops from XML to Flat Fiel Conversion
|
|

April 19th, 2010, 04:03 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Well, my code was XSLT 2.0 too (it uses the tokenize() function), though it could be adapted to work with an XSLT 1.0 processor that has a similar extension function. But I'm sorry, there are limits to the amount of time that I'll put into solving other people's problems, especially with one hand tied behind my back (which is what XSLT 1.0 coding feels like).
Part of the reason for reluctance is that I think you're out of your depth. When we have posted solutions that were incomplete, you haven't had any success in working out why, or in completing the solution by yourself. That makes me feel that if I help you with the next step in the journey, you're going to come straight back wanting help with the next step after that. This is a difficult problem, and it's not a good one to choose for training an XSLT novice; it's quite soluble, but you need some experience on easier problems first. I know that's unhelpful - sorry!
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

April 19th, 2010, 04:12 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by mhkay
Well, my code was XSLT 2.0 too (it uses the tokenize() function), though it could be adapted to work with an XSLT 1.0 processor that has a similar extension function. But I'm sorry, there are limits to the amount of time that I'll put into solving other people's problems, especially with one hand tied behind my back (which is what XSLT 1.0 coding feels like).
Part of the reason for reluctance is that I think you're out of your depth. When we have posted solutions that were incomplete, you haven't had any success in working out why, or in completing the solution by yourself. That makes me feel that if I help you with the next step in the journey, you're going to come straight back wanting help with the next step after that. This is a difficult problem, and it's not a good one to choose for training an XSLT novice; it's quite soluble, but you need some experience on easier problems first. I know that's unhelpful - sorry!
|
I feel sorry for myself too. Because of no experience with XSLT. While replying to your post, i am also trying to learn and fix things. I am not trying to take advantage of you at all.
I appreciate the kindness from You and Martin providing a solution, i still struck with problem. I am sure i can take it from here. Will come back to the forum when i solve the simple problems
An example in this case, i am using the following code to work on replacestring
HTML Code:
<xsl:for-each select="tokenize($this/Audit_Auditees,'~')">
<!--<xsl:variable name="f1v" select="translate(.,'|','*')"/>-->
<xsl:variable name="f1v">
<xsl:call-template name="replaceCharsInString">
<xsl:with-param name="stringIn" select="string(.)"/>
<xsl:with-param name="charsIn" select="'|'"/>
<xsl:with-param name="charsOut" select="'{//}'"/>
</xsl:call-template>
</xsl:variable>
Also to make sure empty tags are not passed to the condition. I am still working on using the following check
HTML Code:
<xsl:choose>
<xsl:when test="contains(Data/Audit_Auditees, '~')">
</xsl:when>
<xsl:otherwise>
</xsl:otherwise>
</xsl:choose>
|
|

April 19th, 2010, 07:12 PM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I think i am running out of option here with XSLT 1.0
I am able to execute the code, but with XSLT Processor which i am using,it's unable process exslt. I am not sure whether supports or not.
any Expertise advice on following error
Exception in thread "main" javax.xml.transform.TransformerException: com.sap.engine.lib.xml.util.NestedException: Could not load class:
HTML Code:
External XSLT processing started...
Processing transformation:
-xml=c:\Documents and Settings\chillhx\Desktop\Projects\Audit\Audit_Test.xml
-xsl=file:///c:/Documents%20and%20Settings/chillhx/Desktop/Projects/Audit/Splitting.xsl
-out=C:\DOCUME~1\chillhx\LOCALS~1\Temp\RES3A7.txt
Exception in thread "main" javax.xml.transform.TransformerException: com.sap.engine.lib.xml.util.NestedException: Could not load class: http://exslt.org/strings required for execution of 'tokenize'
at com.sap.engine.lib.jaxp.TransformerImpl.transform(TransformerImpl.java:251)
at com.sap.engine.lib.xsl.Process.main(Process.java:61)
Caused by: com.sap.engine.lib.xml.util.NestedException: Could not load class: http://exslt.org/strings required for execution of 'tokenize'
at com.sap.engine.lib.xsl.xpath.JLBLibrary.getFunction(JLBLibrary.java:104)
at com.sap.engine.lib.xsl.xpath.LibraryManager.getFunction(LibraryManager.java:76)
at com.sap.engine.lib.xsl.xpath.ETFunction.evaluate(ETFunction.java:98)
at com.sap.engine.lib.xsl.xpath.XPathProcessor.innerProcess(XPathProcessor.java:56)
at com.sap.engine.lib.xsl.xpath.XPathProcessor.process(XPathProcessor.java:43)
at com.sap.engine.lib.xsl.xpath.XPathProcessor.process(XPathProcessor.java:51)
at com.sap.engine.lib.xsl.xslt.XSLForEach.process(XSLForEach.java:83)
at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java:296)
at com.sap.engine.lib.xsl.xslt.XSLForEach.process(XSLForEach.java:116)
at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java:296)
at com.sap.engine.lib.xsl.xslt.XSLTemplate.process(XSLTemplate.java:272)
at com.sap.engine.lib.xsl.xslt.XSLStylesheet.process(XSLStylesheet.java:463)
at com.sap.engine.lib.xsl.xslt.XSLStylesheet.process(XSLStylesheet.java:431)
at com.sap.engine.lib.xsl.xslt.XSLStylesheet.process(XSLStylesheet.java:394)
at com.sap.engine.lib.jaxp.TransformerImpl.transformWithStylesheet(TransformerImpl.java:398)
at com.sap.engine.lib.jaxp.TransformerImpl.transform(TransformerImpl.java:240)
... 1 more
---------
com.sap.engine.lib.xml.util.NestedException: Could not load class: http://exslt.org/strings required for execution of 'tokenize'
at com.sap.engine.lib.xsl.xpath.JLBLibrary.getFunction(JLBLibrary.java:104)
at com.sap.engine.lib.xsl.xpath.LibraryManager.getFunction(LibraryManager.java:76)
at com.sap.engine.lib.xsl.xpath.ETFunction.evaluate(ETFunction.java:98)
at com.sap.engine.lib.xsl.xpath.XPathProcessor.innerProcess(XPathProcessor.java:56)
at com.sap.engine.lib.xsl.xpath.XPathProcessor.process(XPathProcessor.java:43)
at com.sap.engine.lib.xsl.xpath.XPathProcessor.process(XPathProcessor.java:51)
at com.sap.engine.lib.xsl.xslt.XSLForEach.process(XSLForEach.java:83)
at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java:296)
at com.sap.engine.lib.xsl.xslt.XSLForEach.process(XSLForEach.java:116)
at com.sap.engine.lib.xsl.xslt.XSLNode.processFromFirst(XSLNode.java:296)
at com.sap.engine.lib.xsl.xslt.XSLTemplate.process(XSLTemplate.java:272)
at com.sap.engine.lib.xsl.xslt.XSLStylesheet.process(XSLStylesheet.java:463)
at com.sap.engine.lib.xsl.xslt.XSLStylesheet.process(XSLStylesheet.java:431)
at com.sap.engine.lib.xsl.xslt.XSLStylesheet.process(XSLStylesheet.java:394)
at com.sap.engine.lib.jaxp.TransformerImpl.transformWithStylesheet(TransformerImpl.java:398)
at com.sap.engine.lib.jaxp.TransformerImpl.transform(TransformerImpl.java:240)
at com.sap.engine.lib.xsl.Process.main(Process.java:61)
...done
Last edited by chilly; April 20th, 2010 at 03:19 PM..
|
|
 |