Reputation: 313
New to XSLT and cannot find an answer using Google.
I need to write a new XSLT based on an existing one, in that XSLT they use < ext: to add new tags in the resulting XML from what I understand.
Where can I find an explanation of this ?
Is this good practice ?
This is part of the XSLT :
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ax="http://schemas.microsoft.com/dynamics/2008/01/documents/Message" xmlns:purchaserequisition="http://schemas.microsoft.com/dynamics/2008/01/documents/PurchaseRequisition" xmlns:ext="IgepaFormat" version="1.0" exclude-result-prefixes="ext ax purchaserequisition">
<xsl:output method="xml" encoding="ISO-8859-1" version="1.0" standalone="yes" indent="yes" omit-xml-declaration="no" />
<xsl:namespace-alias stylesheet-prefix="ext" result-prefix="#default" />
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
<xsl:template match="ax:Envelope">
<xsl:for-each select="ax:Body/ax:MessageParts/purchaserequisition:PurchaseRequisition">
<ext:ORDERS>
<ext:Envelop>
<ext:RecordType>ENV</ext:RecordType>
<ext:OrderHeader>
<ext:OrderNumber>
<ext:BuyerOrderNumber>
<xsl:value-of select="purchaserequisition:VendPurchOrderJour/purchaserequisition:PurchId" />
</ext:BuyerOrderNumber>
<ext:ListOfMessageID>
<ext:MessageID>
<ext:IDNumber>
<xsl:value-of select="purchaserequisition:VendPurchOrderJour/purchaserequisition:PurchId" />
</ext:IDNumber>
<ext:IDAssignedBy>
<IDAssignedByCoded>1</IDAssignedByCoded>
</ext:IDAssignedBy>
</ext:MessageID>
</ext:ListOfMessageID>
</ext:OrderNumber>
Upvotes: 1
Views: 724
Reputation: 70598
You need to read up on XML "namespaces"
ext:
is a namespace prefix. If you look at the first line of your stylesheet you should see this declaration
xmlns:ext="IgepaFormat"
So, an element <ext:ORDERS>
means the ORDERS element belongs to the namespace "IgepaFormat". Note the prefix "ext" is arbitrary in this case. It is the namespace URI that is important.
It is not really a question of good practise regarding namespaces. You use them if the XML you are outputting requires them (e.g. the application that consumes the XML you produce requires the elements to be in a particular namespace)
Here is one potential link you could read up on them at: https://www.xml.com/pub/a/1999/01/namespaces.html
Upvotes: 2