943,884 Members | Top Members by Rank

Ad:
Dec 3rd, 2008
0

PLMXML to generic xml

Expand Post »
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, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <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)">
  4. <Product id="id2" name="Test" accessRefs="#id3" subType="Item" productId="000019"></Product>
  5. </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, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version='1.0'?>
  2.  
  3. <xsl:stylesheet
  4. version="1.0"
  5. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  6. xmlns:plm="http://www.plmxml.org/Schemas/PLMXMLSchema"
  7. xmlns="http://www.plmxml.org/Schemas/PLMXMLSchema" exclude-result-prefixes="plm">
  8.  
  9. <xsl:strip-space elements="*" />
  10. <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
  11.  
  12. <xsl:template match="/">
  13. <xsl:variable name="elementName" select="name()"/>
  14. <xsl:choose>
  15. <xsl:when test="$elementName = 'PLMXML'">
  16. <xsl:call-template name="PLMXML"></xsl:call-template>
  17. </xsl:when>
  18. <xsl:when test="$elementName = 'Product'">
  19. <xsl:call-template name ="Item"></xsl:call-template>
  20. </xsl:when>
  21. </xsl:choose>
  22.  
  23. </xsl:template>
  24. <xsl:template name="PLMXML">
  25. <xsl:element name="GXML"></xsl:element>
  26. </xsl:template>
  27. <xsl:template name="Item">
  28. <xsl:element name="Item"></xsl:element>
  29. </xsl:template>
  30. </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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vbhatia.81 is offline Offline
2 posts
since Dec 2008
Dec 4th, 2008
0

Re: PLMXML to generic xml

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mlohokare is offline Offline
22 posts
since Oct 2008
Dec 5th, 2008
0

Re: PLMXML to generic xml

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, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:plm="http://www.plmxml.org/Schemas/PLMXMLSchema" exclude-result-prefixes="plm"
  4. >
  5. <xsl:output method="xml" indent="yes"/>
  6. <xsl:template match="/">
  7. <xsl:if test="/plm:PLMXML">
  8. <xsl:call-template name="PLMXML"/>
  9. </xsl:if>
  10. </xsl:template>
  11. <xsl:template name="PLMXML">
  12. <xsl:element name="GXML">
  13. <xsl:if test="/plm:PLMXML/plm:Product">
  14. <xsl:call-template name="Product">
  15. </xsl:call-template>
  16. </xsl:if>
  17. </xsl:element>
  18. </xsl:template>
  19.  
  20. <!--Start Of the Product Template-->
  21. <xsl:template name="Product">
  22. <xsl:param name="id"/>
  23. <xsl:element name="Item">
  24. <xsl:attribute name="id">
  25. <xsl:value-of select="./@productId"/>
  26. </xsl:attribute>
  27.  
  28. <xsl:for-each select="/plm:PLMXML/plm:ProductRevision">
  29. <xsl:call-template name="ProductRevision"/>
  30. </xsl:for-each>
  31. </xsl:element>
  32. </xsl:template>
  33.  
  34. <!--Start of the Product Revision Template-->
  35. <xsl:template name="ProductRevision">
  36. <xsl:element name="ItemRevision"></xsl:element>
  37. </xsl:template>
  38. </xsl:stylesheet>


If you will see in the Product Template I am not able to get the value of the attribute "id"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vbhatia.81 is offline Offline
2 posts
since Dec 2008
Dec 8th, 2008
0

Re: PLMXML to generic xml

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mlohokare is offline Offline
22 posts
since Oct 2008
Jan 14th, 2011
0

i wanna some help regarding plm.

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



Regards,
Fauziya
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fauziya is offline Offline
1 posts
since Jan 2011

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in XML, XSLT and XPATH Forum Timeline: Tree View with XSLT, HTML and Javascript
Next Thread in XML, XSLT and XPATH Forum Timeline: Unable to style xml





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC