Skip to main content
Participant
August 5, 2014
Question

Need help in content chunking..

  • August 5, 2014
  • 1 reply
  • 695 views

Is there a way to extract the XPath results as separate XML files? I am currently looking to chunk a large xml file based on certain tags. I tried using XSLT, but I understand that FM 12 supports only XML version 1.0 and doesnt help in splitting. I am not familiar with Javascripting too. Is there a script or any easy way that can do this job. Any help is appreciated. Thanks!

This topic has been closed for replies.

1 reply

Inspiring
August 5, 2014

XSLT 2.0 is supported since FrameMaker 11.

Try out this example. It uses an XSLT 2.0 function to write each <section> into a separate XML document, and saves the separate documents to c:\temp.

It has worked for me in FM11.

JoH

--- Document: test.xml ---

<?xml version="1.0" encoding="utf-8"?>

<doc>

<section id="s1">

<p>This is section one</p>

</section>

<section id="s2">

<p>This is section two</p>

</section>

</doc>

--- XSL Stylesheet: test.xslt ---

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

<xsl:template match="doc">

  <xsl:apply-templates/>

</xsl:template>

<xsl:template match="section">

  <xsl:variable name="filename">

    <xsl:text>file:///c:\\temp\\</xsl:text>

    <xsl:value-of select="@id"/>

    <xsl:text>.xml</xsl:text>

  </xsl:variable>

  <xsl:result-document href="{$filename}" method="xml">

    <doc>

      <xsl:copy-of select="."/>

    </doc>

  </xsl:result-document>

</xsl:template>

</xsl:stylesheet>

Participant
August 6, 2014

Hi JoH,

Thank you for the quick solution. I tried using it and it threw up an error saying multiple outputs are not possible in the specified location. Here's a detailed description of my requirement.

Scenario

I have an XML structured as shown below:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE Document PUBLIC "-//OASIS//DTD DITA Concept//EN" "technicalContent/dtd/concept.dtd" [

]>

<?Fm Condition Comment Red SINGLE_UNDERLINE show AsIs?>

<?Fm BoolCondExpr "Comment" State 0?>

<document><concept Id = "i1051660"><title>doc title</title>

Blah blah…

Blah blah…

</concept>

</document>

Output: Parse the xml for the tag concept and copy all the contents enclosed within this tag to a new xml file. Each chunk of the output xml must be named with the contents in the title tag.

Thanks for your help!

Inspiring
August 6, 2014

I assume you've already adapted the stylesheet to your needs, as my example should work as-is.

What exactly does the error message say?

Also, you might want to verify that all concept titles in the source document are unique and contain no characters which are not valid in a filename.