Converting a subject schema map with the hierarchy

Post here questions and problems related to editing and publishing DITA content.
gbv34
Posts: 105
Joined: Thu Jan 20, 2022 12:36 pm

Converting a subject schema map with the hierarchy

Post by gbv34 »

Hello,
I wonder if there's any way to convert a subject scheme map as a CSV or a XML file? Or even, if an XSL would already exist?
I used this XSL intended to convert a subject scheme map as ditaval, but it doesn't reproduce the hierarchy between values.
Thank you for your feedback!
------
Gaspard
Radu
Posts: 9473
Joined: Fri Jul 09, 2004 5:18 pm

Re: Converting a subject schema map with the hierarchy

Post by Radu »

Hi,

A subject scheme map is already an XML file. Maybe you could give me more details, an example with how the subject scheme map would look like and how you would like the CSV or XML file generated from it to look like. Also what is your usecase for this?

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
gbv34
Posts: 105
Joined: Thu Jan 20, 2022 12:36 pm

Re: Converting a subject schema map with the hierarchy

Post by gbv34 »

Hello, Radu!
My need is to convert a taxonomy created in a subject scheme map into a CSV file, because my publishing portal uses this type of file for hierarchies.
Here is an example of vocabulary as it is declared in CSV:
image.png
You do not have the required permissions to view the files attached to this post.
------
Gaspard
Radu
Posts: 9473
Joined: Fri Jul 09, 2004 5:18 pm

Re: Converting a subject schema map with the hierarchy

Post by Radu »

Hi,
We do not have a built in solution to achieve exactly what you want, probably a custom XSLT stylesheet can be created for this.
If you give me a precise example with how the Subject scheme map XML content looks like and how the created CSV file should look like (the actual contents of the CSV, not the graph obtained from it) I could try to find some time to construct something like this.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
gbv34
Posts: 105
Joined: Thu Jan 20, 2022 12:36 pm

Re: Converting a subject schema map with the hierarchy

Post by gbv34 »

Hello, Radu!
that would be really kind of you :)
Here are attached a csv file (the expected result) and the initial subject scheme map.
Let me know if that sounds usable.
Thanks a lot!
phylogenetic-tree-csv-and-subject-scheme-map.zip
You do not have the required permissions to view the files attached to this post.
------
Gaspard
Radu
Posts: 9473
Joined: Fri Jul 09, 2004 5:18 pm

Re: Converting a subject schema map with the hierarchy

Post by Radu »

Hi,

I created an XSLT stylesheet to generate something similar to what you want from the subject scheme map:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0" xmlns:oxy="abc">

<xsl:output method="text" indent="no"/>

<xsl:template match="/">
<xsl:apply-templates select="*"/>
</xsl:template>
    
<xsl:template match="text()"/>

<xsl:template match="subjectdef[@keys]">
<xsl:variable name="maxDepth" select="max(//subjectdef[@keys]/count(ancestor::subjectdef[@keys]))"/>
<xsl:for-each select="ancestor::subjectdef[@keys]"><xsl:text>,</xsl:text></xsl:for-each>
<xsl:value-of select="oxy:escapeForCSV(@keys)"/>
<xsl:variable name="reminder" select="$maxDepth - count(ancestor::subjectdef[@keys])"/>
<xsl:call-template name="insertComma">
    <xsl:with-param name="times" select="$reminder"/>
</xsl:call-template>
<xsl:text>
</xsl:text>
<xsl:apply-templates select="*"/>
</xsl:template>
    
<xsl:template name="insertComma">
    <xsl:param name="times"/>
    <xsl:if test="$times > 0">
        <xsl:value-of select="','"/>
        <xsl:call-template name="insertComma">
            <xsl:with-param name="times" select="$times - 1"/>
        </xsl:call-template>
    </xsl:if>
</xsl:template>

<xsl:function name="oxy:escapeForCSV">
<xsl:param name="value"/>
<xsl:value-of select="replace(replace($value, '&quot;', '&quot;&quot;'), ',', '&quot;,&quot;')"/>
</xsl:function>
</xsl:stylesheet>
You can save the XSLT contents above to a separate file named something like "sbj2csv.xsl" and create a transformation scenario in Oxygen to apply it over the subject scheme map file:
https://www.oxygenxml.com/doc/versions/ ... -xslt.html

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
gbv34
Posts: 105
Joined: Thu Jan 20, 2022 12:36 pm

Re: Converting a subject schema map with the hierarchy

Post by gbv34 »

Wouah! That is fantastic, Radu!
Thank you so much. It works like a charm and now, I'm more than never decided to train on XSLT :D
Last edited by gbv34 on Wed Mar 23, 2022 12:33 am, edited 1 time in total.
------
Gaspard
Radu
Posts: 9473
Joined: Fri Jul 09, 2004 5:18 pm

Re: Converting a subject schema map with the hierarchy

Post by Radu »

Hi,
Great, I'm glad this is useful for you, adding below a link to some XSLT training resources I gathered in time:
https://blog.oxygenxml.com/topics/xslt_training.html
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply