PLMXML to generic xml
Please support our XML, XSLT and XPATH advertiser: Programming Forums
![]() |
•
•
Posts: 2
Reputation:
Solved Threads: 0
Hi I am new to xslt and i was trying to generate a generic xml from the plmxml.
Following is the plmxml.xml file
-------------------------------------------------------
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
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
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>
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
•
•
Posts: 20
Reputation:
Solved Threads: 0
Hi,
I am having 1 solution for you pls check if that work for you.
Rewriting ur xml as below
Rewriting your xslt as below;
Output I get as below;
*********
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
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
•
•
Posts: 2
Reputation:
Solved Threads: 0
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.......
If you will see in the Product Template I am not able to get the value of the attribute "id"
<?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"
•
•
Posts: 20
Reputation:
Solved Threads: 0
Hi,
After some modifications you can get the attribute value....
only modified code is as below....
************
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
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
![]() |
Other Threads in the XML, XSLT and XPATH Forum
- Previous Thread: Merged Outlook contacts give too many duplicates
- Next Thread: How to get exact xml file name
•
•
•
•
Views: 919 | Replies: 3 | Currently Viewing: 1 (0 members and 1 guests)





Linear Mode