Can I use a combination of id's in result-document@href?

Here should go questions about transforming XML with XSLT and FOP.
birstrack
Posts: 9
Joined: Wed Jun 29, 2011 12:28 pm

Can I use a combination of id's in result-document@href?

Post by birstrack » Fri Jun 05, 2020 5:44 pm

My problem is that I have to split a learningAssessment topic into several topics, for each child of lcInteraction.
I wrote this:

Code: Select all

<xsl:template match="lcInteraction"> 
        <xsl:for-each select="*"> 
            <xsl:result-document method="xml" href="{concat(/learningAssessment/@id, '-', ./@id, '.xml')}">
                <xsl:element name="qti:assessmentItem">
                    <xsl:attribute name="identifier">
                        <xsl:value-of select="concat(/learningAssessment/@id, '-', ./@id)"/>
                    </xsl:attribute>
                </xsl:element>
            </xsl:result-document>
        </xsl:for-each>
    </xsl:template>
But this isn't working :-(

I want/need as file name the combination of the learningAssessment@id and the id of the lcInteraction child.

Radu
Posts: 7028
Joined: Fri Jul 09, 2004 5:18 pm

Re: Can I use a combination of id's in result-document@href?

Post by Radu » Tue Jun 09, 2020 9:38 am

Hi,

Have you tried to add xsl:messages in your XSLT stylesheet to debug why this does not work?
Like:

Code: Select all

<xsl:message>OUTPUT TO <xsl:value-of select="concat(/learningAssessment/@id, '-', ./@id, '.xml')"/></xsl:message>
I tried to create a sample XML document:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE learningAssessment PUBLIC "-//OASIS//DTD DITA Learning Assessment//EN" "learningAssessment.dtd">
<learningAssessment id="assessment_flp_syq_ylb">
    <title></title>
    <shortdesc></shortdesc>
    <learningAssessmentbody>
        <lcInteraction id="lcInteraction_q5y_yyq_ylb">
            <lcHotspot id="lcHotspot_llc_zyq_ylb">
                <lcQuestion/>
                <lcHotspotMap id="lcHotspotMap_mlc_zyq_ylb">
                    <image id="image_nlc_zyq_ylb"/>
                    <lcArea>
                        <lcAreaShape/>
                        <lcAreaCoords/>
                    </lcArea>
                </lcHotspotMap>
            </lcHotspot>
        </lcInteraction>
    </learningAssessmentbody>
</learningAssessment>
and an XSLT stylesheet:

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">
    <xsl:template match="node() | @*">
        <xsl:copy>
            <xsl:apply-templates select="node() | @*"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="lcInteraction"> 
        <xsl:for-each select="*"> 
            <xsl:message>OUTPUT TO <xsl:value-of select="concat(/learningAssessment/@id, '-', ./@id, '.xml')"/></xsl:message>
            <xsl:result-document method="xml" href="{concat(/learningAssessment/@id, '-', ./@id, '.xml')}">
                <xsl:element name="qti:assessmentItem" xmlns:qti="test">
                    <xsl:attribute name="identifier">
                        <xsl:value-of select="concat(/learningAssessment/@id, '-', ./@id)"/>
                    </xsl:attribute>
                </xsl:element>
            </xsl:result-document>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
and the child element of "lcInteraction" seems to be saved inside a new file. But it depends if this is exactly what you want.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

birstrack
Posts: 9
Joined: Wed Jun 29, 2011 12:28 pm

Re: Can I use a combination of id's in result-document@href?

Post by birstrack » Tue Jun 09, 2020 11:10 am

hi Radu, thanks, this helps/works.

Post Reply