Hi I am new to xslt and i was trying to generate a generic xml from the plmxml.


Following is the plmxml.xml file

<?xml version="1.0" encoding="utf-8"?>

<PLMXML xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema" schemaVersion="6" date="2008-12-02" time="15:33:22" author="Teamcenter V2007.1.3.20080417.00 - PLM@TCLICSRV(498908465)">
<Product id="id2" name="Test" accessRefs="#id3" subType="Item" productId="000019"></Product>
</PLMXML>

-------------------------------------------------------
And in the output i want <GXML> instead of <PLMXML>
and <Item> instead of <Product>
i.e my output xml should look like
<GXML>
<Item>
</Item>
</GXML>
-------------------------------------------------------


and following is my xslt but all i get is an empty file

<?xml version='1.0'?>

<xsl:stylesheet 
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:plm="http://www.plmxml.org/Schemas/PLMXMLSchema"
xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema" exclude-result-prefixes="plm">

<xsl:strip-space elements="*" />
<xsl:output method="xml" indent="yes" encoding="UTF-8"/>

<xsl:template match="/">
<xsl:variable name="elementName" select="name()"/>
<xsl:choose>
<xsl:when test="$elementName = 'PLMXML'">
<xsl:call-template name="PLMXML"></xsl:call-template>
</xsl:when>
<xsl:when test="$elementName = 'Product'">
<xsl:call-template name ="Item"></xsl:call-template>
</xsl:when>
</xsl:choose>

</xsl:template>
<xsl:template name="PLMXML">
<xsl:element name="GXML"></xsl:element>
</xsl:template>
<xsl:template name="Item">
<xsl:element name="Item"></xsl:element>
</xsl:template>
</xsl:stylesheet>

and I am using msxsl Processor.

Can somone please help me understand where am i going wrong? All i could understand is there is some issues with namespace. I will be obliged is someone can shed more light on that or can correct my xslt.

Thanx in advance

Hi,

I am having 1 solution for you pls check if that work for you.

Rewriting ur xml as below

<PLMXML date="2008-12-02" time="15:33:22" author="Teamcenter V2007.1.3.20080417.00 - PLM@TCLICSRV(498908465)">
<Product id="id2" name="Test" accessRefs="#id3" subType="Item" productId="000019">TEST</Product>
</PLMXML>

Rewriting your xslt as below;

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


<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
<xsl:strip-space elements="*" />


<xsl:template match="/">
	<xsl:apply-templates />
</xsl:template>

<xsl:template match="//PLMXML">
<GXML>
	<xsl:apply-templates />
</GXML>
</xsl:template>

<xsl:template match="Product">
<Item>
 <xsl:apply-templates />
</Item>
</xsl:template>
</xsl:stylesheet>

Output I get as below;

<?xml version="1.0" encoding="UTF-8"?>
<GXML>
<Item>TEST</Item>
</GXML>

*********
In above example if you want to display the values of <Product> element as text you can use <xsl:value-of select="@" />. Please check
*********

I think your assumption for namespace is correct but that can be changed in xml as well as xslt.
*********

Cheers,
Mahesh :)

Following is my new xsl and it am able to create the tags but i am not able to write the value of the newly created attributes.......

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:plm="http://www.plmxml.org/Schemas/PLMXMLSchema" exclude-result-prefixes="plm"
>
    <xsl:output method="xml" indent="yes"/>
  <xsl:template match="/">
    <xsl:if test="/plm:PLMXML">
      <xsl:call-template name="PLMXML"/>
    </xsl:if>
  </xsl:template>
  <xsl:template name="PLMXML">
    <xsl:element name="GXML">
      <xsl:if test="/plm:PLMXML/plm:Product">
        <xsl:call-template name="Product">
        </xsl:call-template>
      </xsl:if>
    </xsl:element>
  </xsl:template>
  
  <!--Start Of the Product Template-->
  <xsl:template name="Product">
    <xsl:param name="id"/>
    <xsl:element name="Item">
      <xsl:attribute name="id">
        <xsl:value-of select="./@productId"/>
      </xsl:attribute>
      
      <xsl:for-each select="/plm:PLMXML/plm:ProductRevision">
        <xsl:call-template name="ProductRevision"/>
      </xsl:for-each>
    </xsl:element>
  </xsl:template>
  
  <!--Start of the Product Revision Template-->
  <xsl:template name="ProductRevision">
    <xsl:element name="ItemRevision"></xsl:element>
  </xsl:template>
</xsl:stylesheet>

If you will see in the Product Template I am not able to get the value of the attribute "id"

Hi,

After some modifications you can get the attribute value....

only modified code is as below....

<xsl:template name="PLMXML">
    <xsl:element name="GXML">
      <xsl:if test="/plm:PLMXML/plm:Product">
		  <xsl:for-each select="plm:PLMXML/plm:Product"> <!-- to check all the child nodes otherwise you can see only 1 and very first node -->
        <xsl:call-template name="Product">
			<xsl:with-param name="ids" select="./@id"/> <!-- If you want to check 1 and no other nodes you can remove for-each and rewrite as <xsl:with-param name="ids" select="plm:PLMXML/plm:Product/@id"/> -->
        </xsl:call-template>
		</xsl:for-each>
      </xsl:if>
    </xsl:element>
  </xsl:template>
  
  <!--Start Of the Product Template-->
  <xsl:template name="Product">
    <xsl:param name="ids" />
    <xsl:element name="Item">
      <xsl:attribute name="id">
        <xsl:value-of select="$ids"/>
      </xsl:attribute>

      <xsl:for-each select="/plm:PLMXML/plm:ProductRevision">
        <xsl:call-template name="ProductRevision"/>
      </xsl:for-each>
    </xsl:element>
  </xsl:template>

************
Output for for-each as below...

<GXML>
<Item id="id2"/>
<Item id="id3"/>
</GXML>
************
output without for-each as below
<GXML>
<Item id="id2"/>
</GXML>
************

If that works please mark this thread as solved.

Cheers,
Mahesh :)

Sir,
I want to import objects in teamcenter unified using a plmxml file.
Please help me.

Regards,
Fauziya

This article has been dead for over six months. Start a new discussion instead.