Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xml from Team Center and conforming with XLST

Status
Not open for further replies.

StephenGunn

Programmer
Mar 26, 2019
1
0
0
US
Using XSLT, is it possible to match on values between disparate xml nodes and to combine related data in new XML output?

Objective: To update xml output from Teamcenter, using XSLT, to join together information that is directly related but from separate nodes. So that it is feasible to preview the xml data in an xml reader, to view the data logically grouped together. I give an example below of what I'm asking: The ask is if it's possible.

Note all the xml from Siemen's tool is in something called pmlxml. Ignore that fact and just think of it as standard xml format, albeit it's all attribute based, no elements whatsoever.

Example; I can provide real pmlxml as an example if wanted, but below is representative of the ask and simplifies what I'm trying to ascertain: If possible or not:

<xml>

<topNode>

<Part ID="2", DieType="Draw", Name="Cross Piece">
<NodeA ID="1", yada="red", yada="1.444" />
</Part>

<Part ID="3", DieType="Trim", Name="Support">
<NodeA ID="1", yada="red", yada="1.444" />
</Part>

<Brick ID="4", PartID="2", Name="Layers">
<brickfurthernode id="2", yada = "value" />
</Brick

</topNode>

Run through XSLT… and based on pk and fk relationship, such as on <part ID = "2">, combine information as thus:

<xml>
<Brick ID="4", PartID="2", PartName = "Cross Piece" Name="Layers">

</Brick


 
Stephen,

In short, yes. This is a way to achieve this:

XML:
<?xml version="1.0" encoding="UTF-8"?>
<topNode>
  
  <Part ID="2" DieType="Draw" Name="Cross Piece">
    <NodeA ID="1" yada="red" yadayada="1.444" />
  </Part>
  
  <Part ID="3" DieType="Trim" Name="Support">
    <NodeA ID="1" yada="red" yadayada="1.444" />
  </Part>
  
  <Brick ID="4" PartID="2" Name="Layers">
    <brickfurthernode id="2" yada = "value" />
  </Brick>
  
</topNode>

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform"[/URL]
  version="1.0">

  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/topNode">
    <xsl:element name="transformed">
      <xsl:apply-templates select="Brick" />
    </xsl:element>
  </xsl:template>

  <xsl:template match="Brick">
    <xsl:element name="Brick">
      <xsl:copy-of select="attribute::*"/>
      <xsl:attribute name="PartName"><xsl:value-of select="//Part[@ID = current()/@PartID]/@Name"/></xsl:attribute>
    </xsl:element>
  </xsl:template>

</xsl:stylesheet>

Resulting in:
XML:
<?xml version="1.0" encoding="utf-8"?>
<transformed>
   <Brick ID="4" PartID="2" Name="Layers" PartName="Cross Piece" />
</transformed>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top