在 XSL 中使用 XSL 结果文档标记将 XML 转换为 HTML 未给出所需的结果

问题描述 投票:0回答:1

我们用结果文档(XSLT-2.0 Saxon 处理器)替换了重定向:写入。

早期使用重定向:写入用于获取 3 个输出 HTML,我们可以通过单击其中可用的链接从一个 HTML 导航到另一个 HTML。 现在,使用结果文档,我们只能获得单个 HTML,并且单个 HTML 中仅包含所有 3 个 HTML 的所有数据。另外,在单击链接时,它说无法访问,因为未生成剩余的 HTML。

以下是XSL文件的代码

<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:plm="http://www.plmxml.org/Schemas/PLMXMLSchema"
xmlns:lxslt="http://www.apache.org/xslt"
xmlns:setfile ="com.teamcenter.rac.cme.cmereport.CMEReportXalanExtension">

<xsl:key name="Occurrence" match="plm:Occurrence | plm:WorkAreaOccurrence" use="@id"/>
<xsl:key name="Operation" match="plm:Operation" use="@id"/>
<xsl:key name="OperationRevision" match="plm:OperationRevision" use="@id"/>
<xsl:key name="Process" match="plm:Process | plm:Operation" use="@id"/>
<xsl:key name="ProcessOccurrence" match="plm:ProcessOccurrence | plm:Occurrence | plm:WorkAreaOccurrence" use="@id"/>
<xsl:key name="ProcessRevision" match="plm:ProcessRevision | plm:OperationRevision" use="@id"/>
<xsl:key name="ProcessView" match="plm:ProcessView" use="@id"/>
<xsl:key name="ProcOpRevision" match="plm:ProcessRevision | plm:OperationRevision" use="@id"/>

<lxslt:component prefix="setfile" elements="copy" functions="setFile setTcFile getCurrentDir
        getCurrentImanFileName getCurrentImanFileNamePrefix getNiceName">
  <lxslt:script lang="javaclass" src="com.teamcenter.rac.cme.cmereport.CMEReportXalanExtension"/>
</lxslt:component>

<xsl:output method="html" indent="yes"/>
<xsl:param name="outDir" select="setfile:getCurrentDir(setfile:new())"/>
<xsl:variable name="roid" select="/plm:PLMXML/plm:ProcessView/@rootRefs"/><!-- rootRef instead of prima.. -->
<!-- Assuming that the primaryOccurrenceRef(& NO MULTIPLE ENTRY POINTS) is always a ProcessOccurrence -->
<xsl:variable name="rpoe" select="key('ProcessOccurrence',$roid)"/>
<xsl:variable name="rprid" select="substring-after($rpoe/@instancedRef,'#')"/>
<xsl:variable name="root" select="key('ProcessRevision',$rprid)"/>

<xsl:template match="/">
    <xsl:call-template name="genData">
        <xsl:with-param name="curProc" select="$root"/>
        <xsl:with-param name="occStr" select="$rpoe/@occurrenceRefs"/>
    </xsl:call-template>
</xsl:template>

<xsl:template name="genData">
<xsl:param name="curProc"/>
<xsl:param name="occStr"/>
    <html>
        <head>
            <title>Process: <xsl:value-of select="$curProc/@name"/></title>
        </head>
        <body BGCOLOR="#FFFFFF" link="#0000FF" vlink="#660066">
            <br/>
                        <!-- Support for Foxfire browser requires specific class="sample" on all table elements -->
            <table class="sample"><!-- main table -->
                <xsl:call-template name="heading">
                    <xsl:with-param name="title" select="'Process Report'"/>
                </xsl:call-template>
                                <tr>
                                        <td>
                                                <xsl:variable name="procid">
                                                        <xsl:call-template name="cleanId">
                                                                <xsl:with-param name="id" select="$curProc/@masterRef"/>
                                                        </xsl:call-template>
                                                </xsl:variable>
                                                <xsl:variable name="proc" select="key('Process',$procid)"/>
                                                <xsl:value-of select="concat($proc/@catalogueId,'/',$curProc/@revision,' - ',$curProc/@name)"/>
                                        </td>
                                </tr>

                <tr><!-- main table:row6::sub level -->
                    <td>
                        <hr color="#000000"/>
                        <table class="sample">
                        <tr>
                            <th>Name</th>
                        </tr>
                        <xsl:call-template name="createCL">
                            <xsl:with-param name="chStr" select="$occStr"/>
                        </xsl:call-template>
                        </table>
                    </td>
                </tr>
            </table>
        </body>
    </html>
</xsl:template>

<xsl:template name="createCL">
<xsl:param name="chStr"/>
    <xsl:variable name="genele" select="key('ProcessOccurrence',$chStr)"/>
                <xsl:if test="name($genele)='ProcessOccurrence'">
                    <xsl:call-template name="creCLext">
                        <xsl:with-param name="genel" select="$genele"/>
                    </xsl:call-template>
                </xsl:if>
</xsl:template>

<xsl:template name="creCLext">
<xsl:param name="genel"/>
    <xsl:variable name="procid" select="substring-after($genel/@instancedRef,'#')"/>
    <xsl:variable name="procele" select="key('ProcOpRevision',$procid)"/><!-- ProcessRevision or OperationRevision -->
    <xsl:variable name="pre1" select="substring-after($genel/@predecessorRefs,'#')"/><!--assuming only one id to be present -->
    <xsl:variable name="pre2" select="key('ProcessOccurrence',$pre1)"/>
    <xsl:variable name="preid" select="substring-after($pre2/@instancedRef,'#')"/>
    <xsl:variable name="prele" select="/plm:PLMXML/*[@id=$preid]"/>
    <tr>
    <td align="center"><a>
        <xsl:attribute name="href">
            <xsl:value-of select="concat($procid,'.html')"/>
        </xsl:attribute>
        <xsl:value-of select="$procele/@name"/>
    </a></td>
     
    </tr>
    <result-document href="concat($procid,'.html')">
    <xsl:call-template name="genopr">
                <xsl:with-param name="curOpr" select="$procele"/>
                <xsl:with-param name="genel" select="$genel"/>
            </xsl:call-template>
    </result-document>
</xsl:template>

<xsl:template name="genopr">
<xsl:param name="curOpr"/>
<xsl:param name="genel"/>
    <html>
        <head>
            <title>Operation: <xsl:value-of select="$curOpr/@name"/></title>
        </head>
        <body BGCOLOR="#FFFFFF" link="#0000FF" vlink="#660066">
            <br/>
            <table class="sample"><!-- main table -->
                <xsl:call-template name="heading">
                    <xsl:with-param name="title" select="'Operation Report'"/>
                </xsl:call-template>
                                <tr>
                                        <td>
                                                <xsl:variable name="procid">
                                                        <xsl:call-template name="cleanId">
                                                                <xsl:with-param name="id" select="$curOpr/@masterRef"/>
                                                        </xsl:call-template>
                                                </xsl:variable>
                                                <xsl:variable name="proc" select="key('Process',$procid)"/>
                                                <xsl:value-of select="concat($proc/@catalogueId,'/',$curOpr/@revision,' - ',$curOpr/@name)"/>
                                        </td>
                                </tr>
                
            </table>
        </body>
    </html>

</xsl:template>

<xsl:template name="heading">
<xsl:param name="title"/>
                <tr><!-- main table:row1::heading-->
                    <th>
                        <div align="left">
                        </div>
                        <div align="center"><b><font size="+2"><xsl:value-of select="$title"/></font></b></div><br/>
                    </th>
                </tr>
</xsl:template>
<xsl:template name="cleanId">
    <xsl:param name="id"/>

    <xsl:choose>
        <xsl:when test="contains($id, '#')">
            <xsl:value-of select="substring-after($id,'#')"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$id"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

</xsl:stylesheet>

下面是我们调用转换器以将 XML 转换为 HTML 的代码。

{
         

        // 1. Instantiate a TransformerFactory.
        javax.xml.transform.TransformerFactory tFactory =(SAXTransformerFactory) SAXTransformerFactory.newInstance();

        XslImportResolver myResolve = new XslImportResolver();
        tFactory.setURIResolver( myResolve );

        // 2. Use the TransformerFactory to process the stylesheet Source and
        //                generate a Transformer.
        javax.xml.transform.Transformer transformer = tFactory.newTransformer
                        (new javax.xml.transform.stream.StreamSource(xslLocation));

        // Add debugging output if it is definded in the Registry.
        Registry registry = Registry.getRegistry( this );

        // 3. Use the Transformer to perform the transformation and send the
        //          the output to a Result object.
        transformer.transform( new StreamSource( xmlLocation ),
                new StreamResult( new FileOutputStream( htmlLocation ) ) );
    }

这是转换的 XML(部分)输入

    <?xml version="1.0" encoding="utf-8"?>
<PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema"
 language="en-us" time="13:52:21" schemaVersion="6">
<Header id="id1" traverseRootRefs="#id6" transferContext="tcm_export"></Header>
<Process id="id20" name="PlantBOp_rediined" subType="Mfg0MEPlantBOP" accessRefs="#id13" catalogueId="002927">
<ApplicationRef application="applicationName" label="AfiRcExBJ_LsEB" version="AfiRcExBJ_LsEB"></ApplicationRef></Process>
<Operation id="id41" name="OP" subType="MEOP" accessRefs="#id13" catalogueId="002929">
<ApplicationRef application="applicationName" label="wvtRcExBJ_LsEB" version="wvtRcExBJ_LsEB"></ApplicationRef></Operation>
<Process id="id45" name="process_station" subType="Mfg0MEProcStatn" accessRefs="#id13" catalogueId="002928">
<ApplicationRef application="applicationName" label="gTqRcExBJ_LsEB" version="gTqRcExBJ_LsEB"></ApplicationRef></Process>
<ProcessRevision id="id18" name="PlantBOp_rediined" subType="Mfg0MEPlantBOPRevision" accessRefs="#id13" masterRef="#id20" revision="A">
<ApplicationRef application="applicationName" label="AfiRcExBJ_LsEB" version="AfpRcExBJ_LsEB"></ApplicationRef>
</ProcessRevision>
<OperationRevision id="id39" name="OP" subType="MEOPRevision" accessRefs="#id13" masterRef="#id41" revision="A">
<ApplicationRef application="applicationName" label="wvtRcExBJ_LsEB" version="wzjRcExBJ_LsEB"></ApplicationRef>
</OperationRevision>
<ProcessRevision id="id43" name="process_station" subType="Mfg0MEProcStatnRevision" accessRefs="#id13" masterRef="#id45" revision="A">
<ApplicationRef application="applicationName" label="gTqRcExBJ_LsEB" version="gXgRcExBJ_LsEB"></ApplicationRef>
</ProcessRevision>
<ProcessView id="id4" ruleRefs="#id2" rootRefs="id6" primaryOccurrenceRef="id8">
<ApplicationRef application="applicationName" label="AjiRcExBJ_LsEB/QkqRjxIVJ_LsEB/AAAAAAAAAAAAAA/BOM/"></ApplicationRef>
<ProcessOccurrence id="id6" instancedRef="#id43" associatedAttachmentRefs="#id23 #id26" occurrenceRefs="id28" parentRef="#id8">
<ApplicationRef application="applicationName" label="AjiRcExBJ_LsEB/gfuRcExBJ_LsEB/"></ApplicationRef>
<Transform id="id5">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</Transform>
<AttributeContext id="id21" attributeName="AO_ID" contextRef="#id8"></AttributeContext></ProcessOccurrence>
<ProcessOccurrence id="id8" instancedRef="#id18" associatedAttachmentRefs="#id11 #id17" occurrenceRefs="id6">
<ApplicationRef application="applicationName" label="AjiRcExBJ_LsEB/"></ApplicationRef>
<Transform id="id7">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</Transform>
<AttributeContext id="id9" attributeName="AO_ID" contextRef="#id8"></AttributeContext></ProcessOccurrence>
<ProcessOccurrence id="id28" instancedRef="#id39" associatedAttachmentRefs="#id31 #id34 #id42" parentRef="#id6" configuredActivityRootRef="#id37">
<ApplicationRef application="applicationName" label="AjiRcExBJ_LsEB/BAqRcExBJ_LsEB/gfuRcExBJ_LsEB/"></ApplicationRef>
<Transform id="id27">1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1</Transform>
<AttributeContext id="id29" attributeName="AO_ID" contextRef="#id8"></AttributeContext></ProcessOccurrence></ProcessView>
</PLMXML>

我们希望输出文件能够让用户能够在其中导航。 更短地替代重定向写入。

java xslt xslt-2.0 saxon
1个回答
0
投票
<result-document href="concat($procid,'.html')">

</result-document>

应该是

<xsl:result-document href="concat($procid,'.html')">

</xsl:result-document>
© www.soinside.com 2019 - 2024. All rights reserved.