[英]XSLT map different child of a parent node
I have recently started using XSLT. 我最近开始使用XSLT。 I am trying to get a report of this xml set 我正在尝试获取此xml集的报告
One of xml looks like the below one and named (company_a.xml) xml之一类似于下图,并命名为(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 使用的XSL是
<?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 I am looking for 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 then I am not sure how to fetch empname 但是我不确定如何获取empname
I am using file_list(document($filename)) as there are more than 100 files which has millions of lines to look within 我正在使用file_list(document($ filename)),因为有100多个文件,其中有数百万行可供查找
Please advice. 请指教。
If you 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 you should get a line for each existing empname
. 那么您应该为每个现有的empname
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.