xml - XSLT map different child of a parent node -


i have started using xslt. trying report of xml set

one of xml looks below 1 , named (company_a.xml)

<company title="abc" > <section> <in-proc uid="hr.xml">     <details>         <empname>abcd1</empname>         <id>xyz1</id>         <empname>abcd2</empname>         <id>xyz2</id>         <empname>abcd3</empname>         <id>xyz3</id>     </details> </in-proc>       <out-proc uid="manufacturing.xml">     <title>any</title>     <details>         <empname>abcd4</empname>         <id>xyz4</id>     </details> </out-proc> </section> </company> 

xsl used is

<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:output omit-xml-declaration="yes"/>     <xsl:template match="/">     <xsl:result-document href="emp_data.csv">             <xsl:for-each select="//file">                 <xsl:variable name="filename" select="."/>                 <xsl:variable name="fileid" select="substring-before(., '.xml')"/>                 <xsl:for-each select="document($filename)">                     <xsl:for-each select="company/section/*/details">                         <xsl:variable name="business" select="local-name(..)"/>                         <xsl:variable name="dept" select="substring-before(ancestor::*/@uid, '.xml')"/>                             <xsl:value-of select="concat('&quot;', id , '&quot;,&quot;', empname , '&quot;,&quot;', $fileid, '&quot;,&quot;', $dept, '&quot;,&quot;', $business, '&quot;&#xa;')"/>                     </xsl:for-each>                 </xsl:for-each>             </xsl:for-each>     </xsl:result-document>     </xsl:template> </xsl:stylesheet> 

is giving

xyz1,abcd1,company_a,hr,in-proc xyz4,abcd4,company_a,manufacturing,out-proc 

results looking is

xyz1,abcd1,company_a,hr,in-proc xyz2,abcd2,company_a,hr,in-proc xyz3,abcd3,company_a,hr,in-proc xyz4,abcd4,company_a,manufacturing,out-proc 

i tried using

<xsl:for-each select="id">      <xsl:value-of select="."/> 

but not sure how fetch empname

i using file_list(document($filename)) there more 100 files has millions of lines within

please advice.

if replace

                <xsl:for-each select="company/section/*/details">                     <xsl:variable name="business" select="local-name(..)"/>                     <xsl:variable name="dept" select="substring-before(ancestor::*/@uid, '.xml')"/>                         <xsl:value-of select="concat('&quot;', id , '&quot;,&quot;', empname , '&quot;,&quot;', $fileid, '&quot;,&quot;', $dept, '&quot;,&quot;', $business, '&quot;&#xa;')"/>                 </xsl:for-each> 

with

                <xsl:for-each select="company/section/*/details/empname">                     <xsl:variable name="business" select="local-name(../..)"/>                     <xsl:variable name="dept" select="substring-before(ancestor::*/@uid, '.xml')"/>                         <xsl:value-of select="concat('&quot;', following-sibling::id[1] , '&quot;,&quot;', . , '&quot;,&quot;', $fileid, '&quot;,&quot;', $dept, '&quot;,&quot;', $business, '&quot;&#xa;')"/>                 </xsl:for-each> 

then should line each existing empname.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -