Note that there are some explanatory texts on larger screens.

plurals
  1. POCall Template with Parameter and Output Value - XSLT
    primarykey
    data
    text
    <p>I have an 1 large xml file composed of 2 different xml files. What I want to do is, when I create a CSV file, I want to be able to grab data from the second part of the file that matches the first part. I use a for each loop to go through all of the data in the first portion of the file, and then a nested loop to grab matching data. Here is the XML layout:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;Report_Data&gt; &lt;Report_Entry&gt; &lt;company_id&gt;001&lt;/company_id&gt; &lt;dept&gt;TestDept&lt;/dept&gt; &lt;/Report_Entry&gt; &lt;Report_Entry&gt; &lt;/Report_Entry&gt; &lt;Company_Data&gt; &lt;Report_Entry&gt; &lt;code&gt;1&lt;/code&gt; &lt;name&gt;Test1&lt;/name&gt; &lt;/Report_Entry&gt; &lt;Report_Entry&gt; &lt;code&gt;2&lt;/code&gt; &lt;name&gt;Test2&lt;/name&gt; &lt;/Report_Entry&gt; &lt;/Company_Data&gt; &lt;/Report_Data&gt; </code></pre> <p>What I would like in my CSV is to have the name from the Company_Data node inserted into the output right after the company_id.</p> <p>Here is my XSL File (it currently does not work, it loops through and outputs N/A for each company data node in the output file):</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wd="urn:com.workday/bsvc"&gt; &lt;xsl:output method="text" encoding="utf-8" media-type="text/plain" /&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:variable name="newline" select="'&amp;#x0A;'" /&gt; &lt;xsl:variable name="tab" select="'&amp;#x09;'" /&gt; &lt;xsl:variable name="comma" select="'&amp;#x2C;'" /&gt; &lt;xsl:variable name="padding" select="' '" /&gt; &lt;xsl:variable name="ID" select="concat('COMPANY ID', $padding)" /&gt; &lt;xsl:variable name="NAME" select="concat('COMPANY NAME', $padding)" /&gt; &lt;xsl:variable name="DEPT" select="concat('DEPARTMENT', $padding)" /&gt; &lt;xsl:template match="/"&gt; &lt;xsl:value-of select="$ID"/&gt;&lt;xsl:value-of select="$comma"/&gt; &lt;xsl:value-of select="$NAME"/&gt;&lt;xsl:value-of select="$comma"/&gt; &lt;xsl:value-of select="$DEPT"/&gt;&lt;xsl:value-of select="$comma"/&gt; &lt;xsl:for-each select="/Report_Data/Report_Entry"&gt; &lt;xsl:value-of select="translate(substring(concat(company_id, $padding), 1, string-length($ID)), ',', ' ')" /&gt;&lt;xsl:value-of select="$comma"/&gt; &lt;xsl:call-template name="company_name"&gt; &lt;xsl:with-param name="id_number" select="company_id"&gt;&lt;/xsl:with-param&gt; &lt;/xsl:call-template&gt; &lt;xsl:value-of select="translate(substring(concat(dept, $padding), 1, string-length($DEPT)), ',', ' ')" /&gt;&lt;xsl:value-of select="$comma"/&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;xsl:template name="company_name" match="/wd:Report_Data/wd:Company_Data"&gt; &lt;xsl:param name="id_number"&gt;&lt;/xsl:param&gt; &lt;xsl:for-each select="/wd:Report_Entry"&gt; &lt;xsl:if test="contains($id_number, code)"&gt; &lt;xsl:value-of select="/name/text()"/&gt; &lt;/xsl:if&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>My output looks like this:</p> <pre><code>1, TestDept </code></pre> <p>Instead of:</p> <pre><code>1, Test1, TestDept </code></pre> <p>It is not outputting the value of the <code>name</code> node. How can I get it to display the value?</p> <p>I can add stuff if more info is needed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload