• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Need help in content chunking..

New Here ,
Aug 05, 2014 Aug 05, 2014

Copy link to clipboard

Copied

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!

TOPICS
Scripting

Views

564

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 05, 2014 Aug 05, 2014

Copy link to clipboard

Copied

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 05, 2014 Aug 05, 2014

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 05, 2014 Aug 05, 2014

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 06, 2014 Aug 06, 2014

Copy link to clipboard

Copied

Hi JoH,

Thanks for the tip. You were right!! There were invalid characters in the title and so, I modified the script to read as shown:

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

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

<xsl:template match="document">

  <xsl:apply-templates/>

</xsl:template>

<xsl:template match="concept">

      <xsl:text>file:///D:\\output\\</xsl:text>

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

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

    <xsl:result-document href="{@Id}-output.xml" method="xml">

    <doc>

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

    </doc>

  </xsl:result-document>

</xsl:template>

</xsl:stylesheet>

However, what it does is, just separate the various concept tags and "only" the content (the child nodes are missing) as a single large output file. The splitting doesn't happen. Further, there is no temp file created too. I am using Fm 12.

Thanks for your help!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 06, 2014 Aug 06, 2014

Copy link to clipboard

Copied

<xsl:result-document href="{@Id}-output.xml" method="xml">

You've specified the filename without a path. Therefore the result documents have probably been written to FM's working directory, which might be somewhere like c:\Program Files (x86)\Adobe\AdobeFrameMaker.

To write the result documents to a given directory, you can either specify an absolute path (as in my original example), or (slightly more complex) the path of the source document.

The "-out" file opened automatically in FM after the transformation is none of documents written by <xsl:result-document>, but the main output document for the transformation.

If you only need the result documents containing the separated <concept> nodes, you can simply close the "-out" file.

Further, there is no temp file created too.

Not sure what "temp file" you are referring to.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 07, 2014 Aug 07, 2014

Copy link to clipboard

Copied

Hi JoH,

Thanks for the reply. Yes, the chunks were moving to program files> Adobe FM 12>  folder on the C drive. I have included the path in the script too. But that doesn't seem to work. For another colleague, all the chunks have moved to some random folder.

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

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

<xsl:template match="document">

<xsl:apply-templates/>

</xsl:template>

<xsl:template match="concept">

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

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

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

<xsl:result-document href="{@Id}-output.xml" method="xml">

<concept>

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

</concept>

</xsl:result-document>

</xsl:template>

</xsl:stylesheet>

Do you have any idea as to why is this happening?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 10, 2014 Aug 10, 2014

Copy link to clipboard

Copied

LATEST

Pavrithra,

You are forgetting one essential part of JoH's script: the section where you create the filepath should be assigned to an XSL variable, which is then used in the pathname for the XSL result document. This is indicated in JoH's script but missing from your later version. You have to be more than exact to make XSL do what you want it to do.

Also, I would personally suggest you ask XSL specific questions on one of the XSL-specific (sub)forums on the internet, as the FrameMaker scripting forum is not really the best place to put these questions: it is about FM scripting and there will not nearly be as many XSLT users here as opposed on the XSL-centered (sub)forums. The best forum I know is the XQuery and XPath forum on the IBM DeveloperWorks site.

Kind regards

Jang

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines