RSS Forums RSS

PLMXML to generic xml

Please support our XML, XSLT and XPATH advertiser: Programming Forums
Reply
Posts: 2
Reputation: vbhatia.81 is an unknown quantity at this point 
Solved Threads: 0
vbhatia.81 vbhatia.81 is offline Offline
Newbie Poster

PLMXML to generic xml

  #1  
Dec 3rd, 2008
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
AddThis Social Bookmark Button
Reply With Quote  
Posts: 20
Reputation: mlohokare is an unknown quantity at this point 
Solved Threads: 0
mlohokare mlohokare is offline Offline
Newbie Poster

Re: PLMXML to generic xml

  #2  
Dec 4th, 2008
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
Reply With Quote  
Posts: 2
Reputation: vbhatia.81 is an unknown quantity at this point 
Solved Threads: 0
vbhatia.81 vbhatia.81 is offline Offline
Newbie Poster

Re: PLMXML to generic xml

  #3  
Dec 5th, 2008
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"
Reply With Quote  
Posts: 20
Reputation: mlohokare is an unknown quantity at this point 
Solved Threads: 0
mlohokare mlohokare is offline Offline
Newbie Poster

Re: PLMXML to generic xml

  #4  
Dec 8th, 2008
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the XML, XSLT and XPATH Forum
Views: 919 | Replies: 3 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:09 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC