Note that there are some explanatory texts on larger screens.

plurals
  1. POTransform XML files in a folder to XML files using XSLT
    primarykey
    data
    text
    <p>Solved my own question after few trials and errors. Thanks to all for their help.</p> <p>I have a question about how to transform a set of XML files located in a folder on the local system. I need to transform the files to XML while keeping the original names, which are based on the topic text().</p> <p>I am currently able to transform the a file using the xslt and I get the desired result, but because I have a good number of files it is not practical to transform the files one at a time.</p> <p>My input XML look like the following:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd"&gt; &lt;topic&gt; &lt;title class="- topic/title "&gt; Term &lt;/title&gt; &lt;body class="- topic/body "&gt; &lt;p class="- topic/p "&gt;Paragraph new&lt;/p&gt; &lt;p class="- topic/p "&gt;(See New parag.)&lt;/p&gt; &lt;p class="- topic/p "&gt;(See Next parag.)&lt;/p&gt; &lt;p class="- topic/p "&gt;(See Test.)&lt;/p&gt; &lt;p class="- topic/p "&gt;(See The other parag)&lt;/p&gt; &lt;p class="- topic/p "&gt;(Refer to the conclusion)&lt;/p&gt; &lt;/body&gt; &lt;/topic&gt; </code></pre> <p>and my XSLT is the following</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/" &gt; &lt;!-- This adds DOCTYPE declaration --&gt; &lt;xsl:output method="xml" encoding="UTF-8" doctype-public="-//OASIS//DTD DITA Glossary//EN" name="mygloss" doctype-system="glossary.dtd" omit-xml-declaration="no" indent="yes" /&gt; &lt;xsl:output omit-xml-declaration="no" indent="yes"/&gt; &lt;xsl:param name="files" select="collection('../A/?select=*.dita;recurse=yes')"/&gt; &lt;xsl:template match="node()|@*"&gt; &lt;xsl:copy copy-namespaces="no"&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/"&gt; &lt;xsl:for-each select="$files//topic"&gt; &lt;!--had issues with this portion, but fixed it by changing from topic/&gt;text() to title/text(). --&gt; &lt;xsl:result-document href="outputDITANEW/{title/text()}.dita" format="mygloss"&gt; &lt;glossentry id="{concat('test', generate-id())}"&gt; &lt;glossterm id="{concat('test_title', generate-id())}"&gt; &lt;xsl:value-of select="title"/&gt; &lt;/glossterm&gt; &lt;glossdef&gt; &lt;xsl:for-each select="body"&gt; &lt;xsl:apply-templates/&gt; &lt;/xsl:for-each&gt; &lt;/glossdef&gt; &lt;/glossentry&gt; &lt;/xsl:result-document&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Output XML looks like:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE glossentry PUBLIC "-//OASIS//DTD DITA Glossary//EN" "glossary.dtd"&gt; &lt;glossentry id="test_d2e11"&gt; &lt;glossterm id="new_term_d2e3"&gt; Term &lt;/glossterm&gt; &lt;glossdef&gt; &lt;p&gt;Paragraph new&lt;/p&gt; &lt;p&gt;(See New parag.)&lt;/p&gt; &lt;p&gt;(See Next parag.)&lt;/p&gt; &lt;p&gt;(See Test.)&lt;/p&gt; &lt;p&gt;(See The other parag)&lt;/p&gt; &lt;p&gt;(Refer to the conclusion)&lt;/p&gt; &lt;/glossdef&gt; &lt;/glossentry&gt; </code></pre> <p>I have tried to use xslt collection() and result-document(), but I am unable to make it work.</p> <p>The above xslt gives me this error: A sequence of more than one item is not allowed as the first argument of concat().</p> <p>Hopefully this will give more clarity to my question.</p> <p>Thanks in advance for your help.</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