Page 1 of 1
Converting a subject schema map with the hierarchy
Posted: Mon Mar 21, 2022 4:20 pm
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!
Re: Converting a subject schema map with the hierarchy
Posted: Mon Mar 21, 2022 5:37 pm
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
Re: Converting a subject schema map with the hierarchy
Posted: Mon Mar 21, 2022 6:49 pm
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
Re: Converting a subject schema map with the hierarchy
Posted: Tue Mar 22, 2022 8:34 am
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
Re: Converting a subject schema map with the hierarchy
Posted: Tue Mar 22, 2022 12:48 pm
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
Re: Converting a subject schema map with the hierarchy
Posted: Tue Mar 22, 2022 1:53 pm
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, '"', '""'), ',', '","')"/>
</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
Re: Converting a subject schema map with the hierarchy
Posted: Tue Mar 22, 2022 5:34 pm
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

Re: Converting a subject schema map with the hierarchy
Posted: Tue Mar 22, 2022 5:50 pm
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