Connect
With Us

Using XML documents as Templates in SOLIDWORKS PDM

XML DocumentsXML Templates afford the most flexibility in styling your documents. With this method, the XML can be copied and repeated, while there will only be one associated XSLT file in the SOLIDWORKS PDM vault. The XSLT utilized Extensible Stylesheet Language to transform an XML file into a styled format for display and printing. It is important to note that the document can only be edited from the data card.

First, you must create an XML file that contains the elements you wish to link to the data card. Every XML should start with the following declaration:

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

Next, you must declare where the XSLT will be located:

<?xml-stylesheet type='text/xsl' href='XSLT File Location'?>

TIP: ‘..\’ denotes a parent folder. For example, if your document is located in ‘C:\Vault\Specifications\SPEC-1.xml’ and your stylesheet is located in ‘C:\Vault\Templates\Specification.xslt’ you can specify the location from the XML by using the value ‘..\Templates\Specification.xslt’

Then, the elements should be grouped together in a Root Element as shown below:

<Root Element>

<Element1>Value</Element1>

<Element2>Value</Element2>

</Root Element>

Root Element - Group name that can be referenced from the XSLT

Element1, 2 - Element names to link to the data card

Value - The current value of the Element. This should be left blank and populated by the data card.

Then, you can create an XSLT to stylize the XML for printing and viewing. XSLT files are started similarly to XML:

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

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

The following is recommended to ensure multiline inputs are parsed correctly:

           <xsl:template name="Multiline">

                     <xsl:param name="input" />

                          <xsl:choose>

                                        <xsl:when test="contains($input, '&#10;')">

                                                   <xsl:value-of select="substring-before($input, '&#10;')" /><br />

                                                   <xsl:call-template name="Multiline">

                                                             <xsl:with-param name="input" select="substring-after($input, '&#10;')" />

                                                  </xsl:call-template>

                                        </xsl:when>

                                        <xsl:otherwise>

                                        <xsl:value-of select="$input" />

                                        </xsl:otherwise>

                          </xsl:choose>

           </xsl:template>

Finally, you can create your document with an HTML block. It should be structured similarly to what is below:

<xsl:template match="/Root Element">

  <html>

HTML CODE

</html>

</xsl:template>

Root Element - The group assigned in the XML document.

HTML CODE - The actual code that will be used to display the data.

In the HTML section, it will be necessary to link to the elements created in the XML document. If there is no danger of it being multiline, the following code will display it:

<xsl:value-of select="Element"/>

To display it with proper multiline parsing use the following:

<xsl:call-template name="Multiline">

<xsl:with-param name="input" select="Element"/>

</xsl:call-template>

Finally, the XSLT should be completed by closing the stylesheet tag:

</xsl:stylesheet>

That’s it! The XML document will be used as the actual template file while the style sheet is kept in the templates directory. For more advanced configuration tips, join our online PDM307 Advanced PDM Professional Administrator class.

SOLIDWORKS PDM Administrator

Related Articles

Using Excel as a Reporting Tool in SOLIDWORKS PDM

Replacing Control Logic with a Tab Control: SOLIDWORKS PDM Tech Tip

6 Questions (and Answers) for a Successful PDM Vault Implementation

About the Author

Lindsay EarlyLindsay Early is an Application Engineer Consultant and has been with Fisher Unitech for seven years. Lindsay is a Certified SOLIDWORKS Expert and Elite Application Engineer having earned over 14 SOLIDWORKS Certifications including Mechanical Design, Simulation, and Data Mangement.