xslt

xml – Call REST Request inside XSLT and copy only some elements


I am attempting to make a REST call inside my XSL that will incorporate only parts of the response into the original transformed XML doc. I found one example that talked about using variables and the document() function, but I can’t seem to get it to work.

Here is the original XML document:

<?xml version="1.0" encoding="UTF-8"?>
<PublishPELTEST xmlns="http://www.ibm.com/maximo" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
creationDateTime="2018-02-08T09:15:08-05:00" transLanguage="EN" 
baseLanguage="EN" messageID="1518099308834189587" maximoVersion="7 5 2 12" 
event="0">
  <PELTESTSet>
    <WORKORDER>
      <DESCRIPTION>My Workorder Description</DESCRIPTION>
      <WONUM>MWO-522</WONUM>
      <WOPRIORITY>3</WOPRIORITY>
      <WORKORDERID>2255202</WORKORDERID>
      <ASSIGNMENT>
        <LABORCODE>006325</LABORCODE>
      </ASSIGNMENT>
      <KUBROUNDENTRY>
        <KUBROUNDENTRYID>267433</KUBROUNDENTRYID>
        <LINEID>254735</LINEID>
        <OBSERVATION />
        <KUBROUNDLINE>
          <ASSETNUM>385691</ASSETNUM>
          <METERNAME>VLOPSTAT</METERNAME>
          <SEQUENCE>90</SEQUENCE>
          <ASSET>
            <ASSETID>388391</ASSETID>
            <DESCRIPTION>Asset Description</DESCRIPTION>
            <SERVICEADDRESS>
              <STREETADDRESS>1234 Kingston Pike</STREETADDRESS>
            </SERVICEADDRESS>
          </ASSET>
          <METER>
            <DOMAINID>VLOPSTAT</DOMAINID>
            <METERNAME>VLOPSTAT</METERNAME>
          </METER>
        </KUBROUNDLINE>
      </KUBROUNDENTRY>
      <KUBROUNDENTRY>
        <KUBROUNDENTRYID>267432</KUBROUNDENTRYID>
        <LINEID>254734</LINEID>
        <OBSERVATION />
        <KUBROUNDLINE>
          <ASSETNUM>385691</ASSETNUM>
          <METERNAME>GLEAKGRD</METERNAME>
          <SEQUENCE>80</SEQUENCE>
          <ASSET>
            <ASSETID>388391</ASSETID>
            <DESCRIPTION>Asset2 Description</DESCRIPTION>
            <SERVICEADDRESS>
              <STREETADDRESS>2345 Kingston Pike</STREETADDRESS>
            </SERVICEADDRESS>
          </ASSET>
          <METER>
            <DOMAINID>CASEGRDE</DOMAINID>
            <METERNAME>GLEAKGRD</METERNAME>
          </METER>
        </KUBROUNDLINE>
      </KUBROUNDENTRY>
    </WORKORDER>
  </PELTESTSet>
</PublishPELTEST>

This is the REST request and the result that is returned normally:
http://server.loc.org/maxrest/rest/mbo/alndomain/?domainid=’SKIPRSN’

<?xml version="1.0" encoding="UTF-8"?>
<ALNDOMAINMboSet rsStart="0" xmlns="http://www.ibm.com/maximo" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ALNDOMAIN xmlns="http://www.ibm.com/maximo" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <DOMAINID>KUBSKIPRSN</DOMAINID>
        <VALUE>TRAFFIC</VALUE>
        <DESCRIPTION>Traffic Control Needed</DESCRIPTION>
        <ALNDOMAINID>4906</ALNDOMAINID>
        <VALUEID>KUBSKIPRSN|TRAFFIC</VALUEID>
    </ALNDOMAIN>
    <ALNDOMAIN xmlns="http://www.ibm.com/maximo" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <DOMAINID>KUBSKIPRSN</DOMAINID>
        <VALUE>NOT FOUND</VALUE>
        <DESCRIPTION>Asset Not Found</DESCRIPTION>
        <ALNDOMAINID>4006</ALNDOMAINID>
        <VALUEID>KUBSKIPRSN|NOT FOUND</VALUEID>
    </ALNDOMAIN>
    <ALNDOMAIN xmlns="http://www.ibm.com/maximo" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <DOMAINID>KUBSKIPRSN</DOMAINID>
        <VALUE>SKIP ALL</VALUE>
        <DESCRIPTION>Skip All</DESCRIPTION>
        <ALNDOMAINID>3802</ALNDOMAINID>
        <VALUEID>KUBSKIPRSN|SKIP ALL</VALUEID>
    </ALNDOMAIN>
</ALNDOMAINMboSet>

What I had read previously about this was that you had to add the namespace to your xsl. In this case, I believe the namespace is the same namespace as my origianl XML document. So, I guessed that no other references were necessary.??

With that assumption, I ran the XSL below and it does not pull back any information related to the REST request.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:mea="http://www.ibm.com/maximo" exclude-result-prefixes="mea"
    version="1.0">
    <xsl:output method="xml" cdata-section-elements="" />

    <xsl:template match="/">
      <yyy:createJob xmlns:yyy="http://place.org/mmm/app">
        <job>
          <id />
          <origin>AMS</origin>
          <metaId>
            <xsl:value-of select="descendant::mea:WORKORDERID" />
          </metaId>
          <title>
            <xsl:value-of select="descendant::mea:DESCRIPTION" />
          </title>
          <dispatchGroup>FWSAMS</dispatchGroup>
          <priority>
            <xsl:value-of select="descendant::mea:WOPRIORITY" />
          </priority>
          <assignedTo>
            <xsl:value-of 
                select="descendant::mea:ASSIGNMENT/mea:LABORCODE" />
          </assignedTo>
          <jobDocument>
            <xsl:text disable-output-escaping="yes">&lt;![CDATA[</xsl:text>
              <root>
                <workorderNum>
                  <xsl:value-of select="descendant::mea:WONUM" />
                </workorderNum>
                <xsl:apply-templates mode="copy"
                      select="descendant::mea:KUBROUNDENTRY" />
                <skipReasonDomain>
                  <xsl:variable name="myDomain">
                    <xsl:text>SKIPRSN</xsl:text>
                  </xsl:variable>
                  <xsl:value-of 
 select="document(concat('http://server.loc.org/maxrest/rest/mbo/alndomain/?
 domainid=',$myDomain))/descendant::VALUE"/>
                </skipReasonDomain>
              </root>
              <xsl:text disable-output-escaping="yes">]]&gt;</xsl:text>
            </jobDocument>
            <completionDocument />
          </job>
        </yyy:createJob>
      </xsl:template>

    <xsl:template match="*" mode="copy">
    <xsl:element name="{local-name()}">
        <xsl:apply-templates select="node()" mode="copy" />
    </xsl:element>
    </xsl:template>

    <xsl:template match="text()|comment()" mode="copy">
      <xsl:copy/>
    </xsl:template>

</xsl:stylesheet>

This is the resulting XML document:

<yyy:createJob
xmlns:yyy="http://place.org/mmm/app">
<job>
    <id></id>
    <origin>AMS</origin>
    <metaId>2255202</metaId>
    <title>My Workorder Description</title>
    <dispatchGroup>FWSAMS</dispatchGroup>
    <priority>3</priority>
    <assignedTo>006325</assignedTo>
    <jobDocument>
        <![CDATA[<root><workorderNum>MWO-522</workorderNum><KUBROUNDENTRY><KUBROUNDENTRYID>267433</KUBROUNDENTRYID><LINEID>254735</LINEID><OBSERVATION/><KUBROUNDLINE><ASSETNUM>385691</ASSETNUM><METERNAME>VLOPSTAT</METERNAME><SEQUENCE>90</SEQUENCE><ASSET><ASSETID>388391</ASSETID><DESCRIPTION>Asset Description</DESCRIPTION><SERVICEADDRESS><STREETADDRESS>1234 Kingston Pike</STREETADDRESS></SERVICEADDRESS></ASSET><METER><DOMAINID>VLOPSTAT</DOMAINID><METERNAME>VLOPSTAT</METERNAME></METER></KUBROUNDLINE></KUBROUNDENTRY><KUBROUNDENTRY><KUBROUNDENTRYID>267432</KUBROUNDENTRYID><LINEID>254734</LINEID><OBSERVATION/><KUBROUNDLINE><ASSETNUM>385691</ASSETNUM><METERNAME>GLEAKGRD</METERNAME><SEQUENCE>80</SEQUENCE><ASSET><ASSETID>388391</ASSETID><DESCRIPTION>Asset2 Description</DESCRIPTION><SERVICEADDRESS><STREETADDRESS>2345 Kingston Pike</STREETADDRESS></SERVICEADDRESS></ASSET><METER><DOMAINID>CASEGRDE</DOMAINID><METERNAME>GLEAKGRD</METERNAME></METER></KUBROUNDLINE></KUBROUNDENTRY><skipReasonDomain/></root>]]>
    </jobDocument>
    <completionDocument></completionDocument>
</job>
</yyy:createJob>

My desired output would be:

<yyy:createJob
xmlns:yyy="http://place.org/mmm/app">
<job>
    <id></id>
    <origin>AMS</origin>
    <metaId>2255202</metaId>
    <title>My Workorder Description</title>
    <dispatchGroup>FWSAMS</dispatchGroup>
    <priority>3</priority>
    <assignedTo>006325</assignedTo>
    <jobDocument>
        <![CDATA[<root><workorderNum>MWO-522</workorderNum><KUBROUNDENTRY><KUBROUNDENTRYID>267433</KUBROUNDENTRYID><LINEID>254735</LINEID><OBSERVATION/><KUBROUNDLINE><ASSETNUM>385691</ASSETNUM><METERNAME>VLOPSTAT</METERNAME><SEQUENCE>90</SEQUENCE><ASSET><ASSETID>388391</ASSETID><DESCRIPTION>Asset Description</DESCRIPTION><SERVICEADDRESS><STREETADDRESS>1234 Kingston Pike</STREETADDRESS></SERVICEADDRESS></ASSET><METER><DOMAINID>VLOPSTAT</DOMAINID><METERNAME>VLOPSTAT</METERNAME></METER></KUBROUNDLINE></KUBROUNDENTRY><KUBROUNDENTRY><KUBROUNDENTRYID>267432</KUBROUNDENTRYID><LINEID>254734</LINEID><OBSERVATION/><KUBROUNDLINE><ASSETNUM>385691</ASSETNUM><METERNAME>GLEAKGRD</METERNAME><SEQUENCE>80</SEQUENCE><ASSET><ASSETID>388391</ASSETID><DESCRIPTION>Asset2 Description</DESCRIPTION><SERVICEADDRESS><STREETADDRESS>2345 Kingston Pike</STREETADDRESS></SERVICEADDRESS></ASSET><METER><DOMAINID>CASEGRDE</DOMAINID><METERNAME>GLEAKGRD</METERNAME></METER></KUBROUNDLINE></KUBROUNDENTRY><skipReasonDomain><VALUE>TRAFFIC</VALUE><VALUE>NOT FOUND</VALUE><VALUE>SKIP ALL</VALUE></root>]]>
    </jobDocument>
    <completionDocument></completionDocument>
</job>
</yyy:createJob>

I know this is a lot of information, but I hope it helps someone to understand what I am trying to do and how I might be able to get there. Any information is much appreciated.



لینک منبع

xpath – Find nodes with the same couple of attributes with xslt and add a new node


I need to analyse the following XML input:

<LIST>

    <PRODUCT TYPE="1" REP="0">
        <SUB CAT="1.1" COUNT="2">


            <ITEM  NAME="OCC" BEGIN="0" ND="49">

            </ITEM>


            <ITEM NAME="OCC"  BEGIN="0" END="49">

            </ITEM>

        </SUB>
    </PRODUCT>

    <PRODUCT TYPE="1" REP="1">
        <SUB CAT="1.1" COUNT="1">

            <ITEM  NAME="PRC" BEGIN="0" END="49">

            </ITEM>
        </SUB>
    </PRODUCT>

</LIST>

and transform it with Xslt to obtain the following result:

<LIST>

    <PRODUCT TYPE="1" REP="0">
        <SUB CAT="1.1" COUNT="2">

            <MULTIPLE />
            <ITEM  NAME="OCC" BEGIN="0" END="49">

            </ITEM>

            <MULTIPLE />
            <ITEM NAME="OCC"  BEGIN="0" END="49">

            </ITEM>

        </SUB>
    </PRODUCT>

    <PRODUCT TYPE="1" REP="1">
        <SUB CAT="1.1" COUNT="1">
            <MULTIPLE />
            <ITEM  NAME="PRC" BEGIN="0" END="49">

            </ITEM>
        </SUB>
    </PRODUCT>

</LIST>

What I need to do is to check that the BEGIN and END of the ITEMS in two different PRODUCT node are the same, and if this is the case add the MULTIPLE node as a flag.
Any idea on how to proceed?
This is how I thought it could work:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:template match="//PRODUCT[@TYPE='1']/SUB[@CAT='1.1']/ITEM">
		
		
<xsl:if test="//PRODUCT[@TYPE='1']/SUB[@CAT='1.1']/ITEM /RULE (@BEGIN &lt;= current()/@BEGIN) and (@END &gt;= current()/@END)]">

			
		<xsl:element name="MULTIPLE">
										
		</xsl:element>	

			
		</xsl:if>

				
		<xsl:copy>
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
		
</xsl:template>

</xsl:stylesheet>



لینک منبع