1
votes

I'm very new to xslt and trying to learn. The focus to transform my data xml and bind the output xml to the adobe form.

I have a xml of the following structure.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<envelope xmlns="http://www.mydata.de/xem/reporting/datafile">
<sources>
    <source>
        <data>
            <REPORT>
                <EM_ESOURCE>
                    <EM_ES_MEASURE>
                        <ID>1037343</ID>
                        <ES_ID>1006222</ES_ID>
                        <ES_NAME>MFC-D-002</ES_NAME>
                        <EM_MAT_NAME>Cyprinella leedsi</EM_MAT_NAME>
                        <START_DATE>1/19/98</START_DATE>
                        <LABORATORY>Thornton</LABORATORY>
                        <LC50>&gt;100%</LC50>
                        <TESTTYPE/>
                        <IC25/>
                    </EM_ES_MEASURE>
                    <EM_ES_MEASURE>
                        <ID>1037344</ID>
                        <ES_ID>1006222</ES_ID>
                        <ES_NAME>MFC-D-002</ES_NAME>
                        <EM_MAT_NAME>C Dubia</EM_MAT_NAME>
                        <START_DATE>3/2/98</START_DATE>
                        <LABORATORY>Thornton</LABORATORY>
                        <LC50>&gt;120%</LC50>
                        <TESTTYPE>Routine</TESTTYPE>
                        <IC25/>
                    </EM_ES_MEASURE>
                </EM_ESOURCE>
            </REPORT>
        </data>
    </source>
</sources>

This is the result of one of the queries. The Adobe report requires the materials to be shown always in a particular order regardless of what the query returns. So I decided to hardcode the order of materials in the xsl internally, loop on this list and then fetch corresponding "LC50" values from the data xml.

Following is the xsl that I started:

<?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rep="http://www.technidata.de/xem/reporting/datafile"
xmlns:s="http:/materials.data"
xmlns:java="http://xml.apache.org/xslt/java">
<xsl:output method="html" omit-xml-declaration="yes" encoding="UTF-8"/>      
<!-- Suppress copy of restrictions -->
<!--xsl:template match="text()|@*"/-->  
<xsl:key name="material-lookup" match="s:material" use="s:name"/>
<xsl:template match="/">
 <REPORT>
        <HEADERS>
            <STARTDATE><xsl:value-of select="substring(/rep:envelope/rep:sources/rep:restrictions/rep:START_DATE,1,10)"/></STARTDATE>
            <ENDDATE><xsl:value-of select="substring(/rep:envelope/rep:sources/rep:restrictions/rep:START_DATE,16,24)"/></ENDDATE>
            <FACILITY><xsl:value-of select="normalize-space(/rep:envelope/rep:sources/rep:restrictions/rep:ID_ATTRIBUTE_ID_NAME)"/></FACILITY>
        </HEADERS>
        <MATERIALS>         
        </MATERIALS>
         </REPORT></xsl:template>
     <s:materials>
<s:material>
    <s:name>Cyprinella leedsi</s:name>
    <s:parameter>LC(ROUTINE) </s:parameter>
</s:material>
 <s:material>
    <s:name>C Dubia</s:name>
    <s:parameter>LC50(ROUTINE) </s:parameter>
 </s:material>
</s:materials>
</xsl:stylesheet>

I'm not sure how to fill in the the MATERIALS node with the materials in the order defined in the xslt and their corresponding LC50 values from the data xml.

1
Can you please give an example of what the XML output for your above input XML should look like? - StuartLC

1 Answers

0
votes

Use the document('') function to XPath into the XSLT file itself.