Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to select elements in namespace scope and get rid of empty default namespace in the output
    primarykey
    data
    text
    <p>I need to transform the following input file</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt; &lt;env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope"&gt; &lt;wsa:Action&gt;http://worksite.imanage.com/SearchDocumentsResponse&lt;/wsa:Action&gt; &lt;wsa:MessageID&gt;urn:uuid:b9b79a0f-b4de-4686-9c54-51c5a7f99331&lt;/wsa:MessageID&gt; &lt;wsa:RelatesTo&gt;urn:uuid:8e88f531-8369-4557-80bf-e8a9835d8eb3&lt;/wsa:RelatesTo&gt; &lt;wsa:To&gt;http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous&lt;/wsa:To&gt; &lt;wsse:Security&gt; &lt;wsu:Timestamp wsu:Id="Timestamp-ea526ce6-ca66-4aaf-aae9-cf2fe8d5cbad"&gt; &lt;wsu:Created&gt;2011-06-01T07:09:20Z&lt;/wsu:Created&gt; &lt;wsu:Expires&gt;2011-06-01T07:14:20Z&lt;/wsu:Expires&gt; &lt;/wsu:Timestamp&gt; &lt;/wsse:Security&gt; &lt;/env:Header&gt; &lt;soap:Body&gt; &lt;SearchDocumentsResult xmlns="http://worksite.imanage.com"&gt; &lt;Documents&gt; &lt;Document&gt; &lt;ObjectID&gt;!nrtdms:0:!session:PTHT096:!database:Technical:!document:803226,1:&lt;/ObjectID&gt; &lt;Database&gt;Technical&lt;/Database&gt; &lt;Profile&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileDocNum&lt;/AttributeID&gt; &lt;Value&gt;803226&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileDescription&lt;/AttributeID&gt; &lt;Value&gt;TC-D60-1087 - Compressor C-301C Installation Work Platform General Arrangement&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileVersion&lt;/AttributeID&gt; &lt;Value&gt;1&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileCustom3&lt;/AttributeID&gt; &lt;Value&gt;CV&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileDatabase&lt;/AttributeID&gt; &lt;Value&gt;Technical&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileExtension&lt;/AttributeID&gt; &lt;Value&gt;ACROBAT&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;/Profile&gt; &lt;/Document&gt; &lt;/Documents&gt; &lt;/SearchDocumentsResult&gt; &lt;/soap:Body&gt; &lt;/soap:Envelope&gt; </code></pre> <p>into the following output file</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt; &lt;env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope"&gt; &lt;wsa:Action&gt;http://worksite.imanage.com/SearchDocumentsResponse&lt;/wsa:Action&gt; &lt;wsa:MessageID&gt;urn:uuid:b9b79a0f-b4de-4686-9c54-51c5a7f99331&lt;/wsa:MessageID&gt; &lt;wsa:RelatesTo&gt;urn:uuid:8e88f531-8369-4557-80bf-e8a9835d8eb3&lt;/wsa:RelatesTo&gt; &lt;wsa:To&gt;http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous&lt;/wsa:To&gt; &lt;wsse:Security&gt; &lt;wsu:Timestamp wsu:Id="Timestamp-ea526ce6-ca66-4aaf-aae9-cf2fe8d5cbad"&gt; &lt;wsu:Created&gt;2011-06-01T07:09:20Z&lt;/wsu:Created&gt; &lt;wsu:Expires&gt;2011-06-01T07:14:20Z&lt;/wsu:Expires&gt; &lt;/wsu:Timestamp&gt; &lt;/wsse:Security&gt; &lt;/env:Header&gt; &lt;soap:Body&gt; &lt;SearchDocumentsResult xmlns="http://worksite.imanage.com"&gt; &lt;Documents&gt; &lt;Document&gt; &lt;ObjectID&gt;!nrtdms:0:!session:PTHT096:!database:Technical:!document:803226,1:&lt;/ObjectID&gt; &lt;Database&gt;Technical&lt;/Database&gt; &lt;Profile&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileDocNum&lt;/AttributeID&gt; &lt;Value&gt;803226&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileDescription&lt;/AttributeID&gt; &lt;Value&gt;TC-D60-1087 - Compressor C-301C Installation Work Platform General Arrangement&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileVersion&lt;/AttributeID&gt; &lt;Value&gt;1&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileCustom3&lt;/AttributeID&gt; &lt;Value&gt;CV&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileDatabase&lt;/AttributeID&gt; &lt;Value&gt;Technical&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileExtension&lt;/AttributeID&gt; &lt;Value&gt;pdf&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;/Profile&gt; &lt;/Document&gt; &lt;/Documents&gt; &lt;/SearchDocumentsResult&gt; &lt;/soap:Body&gt; &lt;/soap:Envelope&gt; </code></pre> <p>I have written the following stylesheet to do the job</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" xmlns:xs = "http://www.w3.org/2001/XMLSchema" xmlns:soap = "http://www.w3.org/2003/05/soap-envelope" xmlns:w = "http://worksite.imanage.com" exclude-result-prefixes="#all" version="2.0"&gt; &lt;xsl:output indent="yes"/&gt; &lt;xsl:template match="element()"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="@*,node()"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="attribute()|text()|comment()|processing-instruction()"&gt; &lt;xsl:copy/&gt; &lt;/xsl:template&gt; &lt;xsl:template match = "//w:ProfileItem[6]/child::w:Value"&gt; &lt;xsl:call-template name="changeDocumentExtension"/&gt; &lt;/xsl:template&gt; &lt;xsl:template name = "changeDocumentExtension"&gt; &lt;xsl:variable name="iManageExtension" as = "xs:string" select="//w:AttributeID[. = 'imProfileExtension']/following::w:Value" /&gt; &lt;xsl:choose&gt; &lt;xsl:when test="$iManageExtension eq 'ACROBAT'"&gt; &lt;Value&gt;pdf&lt;/Value&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$iManageExtension eq 'ANSI'"&gt; &lt;Value&gt;txt&lt;/Value&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$iManageExtension eq 'EXCEL'"&gt; &lt;Value&gt;xsl&lt;/Value&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$iManageExtension eq 'EXCELX'"&gt; &lt;Value&gt;xslx&lt;/Value&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$iManageExtension eq 'PDF230'"&gt; &lt;Value&gt;pdf&lt;/Value&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$iManageExtension eq 'WORD'"&gt; &lt;Value&gt;doc&lt;/Value&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$iManageExtension eq 'WORDX'"&gt; &lt;Value&gt;docx&lt;/Value&gt; &lt;/xsl:when&gt; &lt;xsl:when test="$iManageExtension eq 'WORDXT'"&gt; &lt;Value&gt;docx&lt;/Value&gt; &lt;/xsl:when&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>This is the output that I get</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"&gt; &lt;env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope"&gt; &lt;wsa:Action&gt;http://worksite.imanage.com/SearchDocumentsResponse&lt;/wsa:Action&gt; &lt;wsa:MessageID&gt;urn:uuid:b9b79a0f-b4de-4686-9c54-51c5a7f99331&lt;/wsa:MessageID&gt; &lt;wsa:RelatesTo&gt;urn:uuid:8e88f531-8369-4557-80bf-e8a9835d8eb3&lt;/wsa:RelatesTo&gt; &lt;wsa:To&gt;http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous&lt;/wsa:To&gt; &lt;wsse:Security&gt; &lt;wsu:Timestamp wsu:Id="Timestamp-ea526ce6-ca66-4aaf-aae9-cf2fe8d5cbad"&gt; &lt;wsu:Created&gt;2011-06-01T07:09:20Z&lt;/wsu:Created&gt; &lt;wsu:Expires&gt;2011-06-01T07:14:20Z&lt;/wsu:Expires&gt; &lt;/wsu:Timestamp&gt; &lt;/wsse:Security&gt; &lt;/env:Header&gt; &lt;soap:Body&gt; &lt;SearchDocumentsResult xmlns="http://worksite.imanage.com"&gt; &lt;Documents&gt; &lt;Document&gt; &lt;ObjectID&gt;!nrtdms:0:!session:PTHT096:!database:Technical:!document:803226,1:&lt;/ObjectID&gt; &lt;Database&gt;Technical&lt;/Database&gt; &lt;Profile&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileDocNum&lt;/AttributeID&gt; &lt;Value&gt;803226&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileDescription&lt;/AttributeID&gt; &lt;Value&gt;TC-D60-1087 - Compressor C-301C Installation Work Platform General Arrangement&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileVersion&lt;/AttributeID&gt; &lt;Value&gt;1&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileCustom3&lt;/AttributeID&gt; &lt;Value&gt;CV&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileDatabase&lt;/AttributeID&gt; &lt;Value&gt;Technical&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;ProfileItem&gt; &lt;AttributeID&gt;imProfileExtension&lt;/AttributeID&gt; &lt;Value xmlns=""&gt;pdf&lt;/Value&gt; &lt;/ProfileItem&gt; &lt;/Profile&gt; &lt;/Document&gt; &lt;/Documents&gt; &lt;/SearchDocumentsResult&gt; &lt;/soap:Body&gt; &lt;/soap:Envelope&gt; </code></pre> <p>I would like to get some help with the following issues:</p> <ol> <li><p>There is an unwanted xmlns="" element in the output that can't be removed using the exclude-result-prefixes attribute. I don't know how to get rid of it.</p></li> <li><p>The stylesheet has two long XPaths. They do the job and point to the right elements but I can't help but cringe every time I look at them. If someone could offer a shorter, cleaner alternative, I'd really appreciate it.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload