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

August 11th, 2013, 02:37 PM
|
|
Registered User
|
|
Join Date: Aug 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
multiple xml output using xslt
i am trying to generate multiple xml file using xslt.
my input.xml file is
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:getDocumentByKeyResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://www.taleo.com/ws/integration/toolkit/2005/07">
<Document xmlns="http://www.taleo.com/ws/integration/toolkit/2005/07">
<Attributes>
<Attribute name="duration">0:00:00.084</Attribute>
<Attribute name="count">7</Attribute>
<Attribute name="entity">Requisition</Attribute>
<Attribute name="mode">XML</Attribute>
<Attribute name="version">http://www.taleo.com/ws/tee800/2009/01</Attribute>
</Attributes>
<Content>
<ExportXML xmlns="http://www.taleo.com/ws/integration/toolkit/2005/07">
<record>
<field name="ContestNumber">1300000F</field>
<field name="ManagerRequisitionTitle">Project Manager</field>
</record>
<record>
<field name="ContestNumber">1300000H</field>
<field name="ManagerRequisitionTitle">Project Manager</field>
</record>
<record>
<field name="ContestNumber">1300000T</field>
<field name="ManagerRequisitionTitle">Project Manager</field>
</record>
<record>
<field name="ContestNumber">13000018</field>
<field name="ManagerRequisitionTitle">Project Manager</field>
</record>
<record>
<field name="ContestNumber">000123</field>
<field name="ManagerRequisitionTitle">Project Manager</field>
</record>
<record>
<field name="ContestNumber">1300000R</field>
<field name="ManagerRequisitionTitle">Project Manager</field>
</record>
<record>
<field name="ContestNumber">13000016</field>
<field name="ManagerRequisitionTitle">Project Manager</field>
</record>
</ExportXML>
</Content>
</Document>
</ns1:getDocumentByKeyResponse>
</soapenv:Body>
</soapenv:Envelope>
my xslt is sample.xslt
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pDest" select="'file:///c:/temp/'"/>
<xsl:template match="*[starts-with(name(),'ExportXML')]">
<xsl:for-each select="record">
<xsl:result-document href="{$pDest}section{position()}.xml">
<JobPositionPostings>
<JobPositionPosting>
<xsl:apply-templates select="*:field[starts-with(@name,'ContestNumber')]"/>
<JobDisplayOptions>
<xsl:apply-templates select="*:field[starts-with(@name,'ManagerRequisitionTitle')]"/>
</JobDisplayOptions>
</JobPositionPosting>
</JobPositionPostings>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
i am not getting proper output. i want that every input <record> tag data comes in seprate file like this
</JobPositionPostings><JobPositionPostings>
<JobPositionPosting>
<contestnumber>13000016</contestnumber>
<JobDisplayOptions>
<managerrequisitiontitle>Project Manager</managerrequisitiontitle>
</JobDisplayOptions>
</JobPositionPosting>
</JobPositionPostings>
please suggest me any solution.thanks in advance.
|
|

August 11th, 2013, 02:56 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
(a) What output are you getting?
(b) What XSLT processor are you using?
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|

August 11th, 2013, 04:18 PM
|
|
Registered User
|
|
Join Date: Aug 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
multiple xml file in result
hi mhkay,
thanks for ur reply,
i am very new to xslt transform.i am using Taleo connect client tool for transform which uses xslt 2.0 .
when i passed the above xslt no output is cming due to <ExportXml> having namespace so only.
this is my xslt which return result.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pDest" select="'file:///c:/temp/'"/>
<xsl:template match="*[starts-with(name(), 'record')]">
<xsl:result-document href="{$pDest}section{position()}.xml">
<JobPositionPostings>
<JobPositionPosting>
<xsl:apply-templates select="*:field[starts-with(@name,'ContestNumber')]"/>
<JobDisplayOptions>
<xsl:apply-templates select="*:field[starts-with(@name,'ManagerRequisitionTitle')]"/>
</JobDisplayOptions>
</JobPositionPosting>
</JobPositionPostings>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
i got the output
<?xml version="1.0" encoding="UTF-8"?>
<JobPositionPostings>
<JobPositionPosting>13000016<JobDisplayOptions>Pro ject Manager</JobDisplayOptions>
</JobPositionPosting>
</JobPositionPostings>
but i got only last row <record> data.i m nt able to put for-each on record tag as i posted in last xslt post.please suggest me how to get all seprate file.thanks in advance
Last edited by adsingh; August 11th, 2013 at 04:20 PM..
|
|

August 11th, 2013, 04:23 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Try specifying the xpath-default-namespace attribute on your stylesheet element to be the Taleo namespace and you might be more luck.
|
|

August 11th, 2013, 04:42 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I haven't come across Taleo before. I took a quick look at the documentation and it appears to use Saxon behind the scenes. I suggest you try running the transformation outside the Taleo environment (e.g. from the command line) to see if that works. Use the -t option which will tell you what result documents are being written. It's possible that Taleo is writing the files, but not where you expect to find them.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|

August 11th, 2013, 04:49 PM
|
|
Registered User
|
|
Join Date: Aug 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi mhkay,
thanks for ur reply.
i am very new to xslt.i am using taleo connect client tool for xslt transform which use xslt 2.0.
i am posting here xslt for which i got only last row of record data. my xslt is
testing.xslt
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pDest" select="'file:///c:/temp/'"/>
<xsl:template match="*[starts-with(name(), 'record')]">
<xsl:result-document href="{$pDest}section{position()}.xml">
<JobPositionPostings>
<JobPositionPosting>
<xsl:apply-templates select="*:field[starts-with(@name,'ContestNumber')]"/>
<JobDisplayOptions>
<xsl:apply-templates select="*:field[starts-with(@name,'ManagerRequisitionTitle')]"/>
</JobDisplayOptions>
</JobPositionPosting>
</JobPositionPostings>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
i got only one output file is
section1.xml
<?xml version="1.0" encoding="UTF-8"?>
<JobPositionPostings>
<JobPositionPosting>13000016<JobDisplayOptions>Pro ject Manager</JobDisplayOptions>
</JobPositionPosting>
</JobPositionPostings>
i expected that output file number ll equal to record tag.but i am getting only last tag vaue. my privious posted xslt not returning anything due to <ExportXML> tag having namespace i think.please suggest me any solution.
|
|

August 11th, 2013, 04:57 PM
|
|
Registered User
|
|
Join Date: Aug 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i checked in c:\temp\ folder.its creating only one file name with section1.xml
i have one doubt can i write this
<xsl:template match="*[starts-with(name(),'ExportXML')]">
because it having namespace.its not parsing that.
i am getting result only one file when i wrote.
<xsl:template match="*[starts-with(name(),'record')]">
because after this on which condition i ll write for each i am not getting.
|
|

August 11th, 2013, 05:10 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
I can't see anything wrong with the code, but using name() is inadvisable because it's sensitive to the choice of namespace prefixes.
Best practice is to bind a namespace prefix
Code:
xmlns:p="http://www.taleo.com/ws/integration/toolkit/2005/07"
in the xsl:stylesheet element, and then use
match="p:record"
match="p:field"
etc.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|
 |