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('"', id , '","', empname , '","', $fileid, '","', $dept, '","', $business, '"
')"/> </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('"', id , '","', empname , '","', $fileid, '","', $dept, '","', $business, '"
')"/> </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('"', following-sibling::id[1] , '","', . , '","', $fileid, '","', $dept, '","', $business, '"
')"/> </xsl:for-each>
then should line each existing empname
.
Comments
Post a Comment