logo
down
shadow

XSLT to copy element without default/old namespace


XSLT to copy element without default/old namespace

By : madego
Date : November 27 2020, 09:01 AM
I wish this helpful for you I'm converting from one XML document to another XML document by using XSLT. Both the input and output document types are in different default namespaces. I used to transform first and then filter with JAXB against the output schema. My requirement is: If publisher/catalogue/cd11/year is available/exist in the input xml then a new element with value need to created as publisher/catalogue/cd22 = 'New Release' in the out put xml. (fyi. publisher/catalogue/cd22 is exist in output schema) , As simple as this:
code :
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output standalone="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:param name="pNewNS" select="'http://example.com/'"/>
 <xsl:variable name="vOldNS" select="namespace-uri(/*)"/>

  <xsl:template match="@*"><xsl:copy/></xsl:template>

  <xsl:template match="*[namespace-uri() eq $vOldNS]">
    <xsl:element name="{name()}" namespace="{$pNewNS}">
      <xsl:apply-templates select="@*|node()"/>
    </xsl:element>
  </xsl:template>

  <xsl:template priority="3" match="*[@id eq 'd1']/*[*[name() = 'year']]">
    <xsl:next-match/>
    <xsl:element name="cd22" namespace="{$pNewNS}">New Release</xsl:element>
  </xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://www.altova.com">
    <publisher>
        <Name id="d123">
            <Location>Chicago</Location>
        </Name>
        <catalogue id="d1" >
            <cd11 id="d2">
                <title>Empire Burlesque</title>
                <artist>Bob Dylan</artist>
                <year>1985</year>
            </cd11>
        </catalogue>
        <catalogue id="d3" >
            <cd11 id="d4">
                <title>Jurassic World</title>
                <artist>Chris Pratt</artist>
            </cd11>
        </catalogue>    
    </publisher>
</root>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root xmlns="http://example.com/">
   <publisher>
      <Name id="d123">
         <Location>Chicago</Location>
      </Name>
      <catalogue id="d1">
         <cd11 id="d2">
            <title>Empire Burlesque</title>
            <artist>Bob Dylan</artist>
            <year>1985</year>
         </cd11>
         <cd22>New Release</cd22>
      </catalogue>
      <catalogue id="d3">
         <cd11 id="d4">
            <title>Jurassic World</title>
            <artist>Chris Pratt</artist>
         </cd11>
      </catalogue>
   </publisher>
</root>


Share : facebook icon twitter icon
XSLT root tag namespace instead of element attribute namespace

XSLT root tag namespace instead of element attribute namespace


By : Edwin Morales
Date : March 29 2020, 07:55 AM
this one helps. You need to insert the namespace node onto the document element of your result tree. There are several ways to do this, depending on whether you're using XSLT 1.0 or 2.0. The following is a 2.0 solution. I'm assuming that you're doing a modified identity transform on the input document (your question didn't really specify):
code :
<xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <!-- special rule for the document element -->
  <xsl:template match="/*">
    <xsl:copy>
      <!-- Add a namespace node -->
      <xsl:namespace name="mynamespace" select="'somenamespace'"/>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <!-- the identity template -->
  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <!-- the rest of your rules -->

</xsl:stylesheet>
XSLT to copy element without namespace

XSLT to copy element without namespace


By : user7369918
Date : March 29 2020, 07:55 AM
will help you The xmlns="" is required because you're asserting a default namespace (with xmlns="http://www.bazaarvoice.com/xs/PRR/ProductFeed/5.6") and then outputting nodes which are not in that namespace. For XML to represent that properly, it has to cancel the default namespace.
You haven't told us how validation is failing. If it's failing because those nodes should be in the specified namespace, they need to either be in that namespace before you copy them, or you need to replace the xsl:copy-of operation with one that explicitly reconstructs them by extracting their localname and using that and the desired namespace as parameters of an xsl:element operation. The items listed at right under Related will tell you more about this.
How to add attributes with namespace with XSLT when there is a default namespace on the XML

How to add attributes with namespace with XSLT when there is a default namespace on the XML


By : Fran Blythe
Date : March 29 2020, 07:55 AM
I hope this helps .
I also need to keep the default namespace (which can change from document to document
code :
<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:deltaxml="http://www.deltaxml.com/ns/well-formed-delta-v1">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="*:section[@id]">
    <xsl:copy>
        <xsl:attribute name="deltaxml:key" select="@id"/>
        <xsl:apply-templates select="@*, node()"/>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>
<section xmlns="http://quark.com/smartcontent/2.0" 
         id="_63f6a0c9-bac8-4a15-854c-03d80bd46b64" 
         type="clientFactsheet">
<!-- content -->
</section>
<?xml version="1.0" encoding="UTF-8"?>
<section xmlns="http://quark.com/smartcontent/2.0"
         xmlns:deltaxml="http://www.deltaxml.com/ns/well-formed-delta-v1"
         deltaxml:key="_63f6a0c9-bac8-4a15-854c-03d80bd46b64"
         id="_63f6a0c9-bac8-4a15-854c-03d80bd46b64"
         type="clientFactsheet"><!-- content --></section>
How to copy parent node namespace to child element using xslt?

How to copy parent node namespace to child element using xslt?


By : user3221978
Date : March 29 2020, 07:55 AM
I hope this helps . Here is the solution (by Transforming the XML Data using Java's XSLT APIs),
As you may also have noticed.. JAXB alone cannot meet this requirement, but after marshalling the object to a formatted XML String (as u have shown) you can then post process/transform it accordingly using a suitable XSLT file
code :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:strip-space elements="TrackAndTrace"/> 
    <xsl:strip-space elements="Request"/> 

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

</xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="w3.org/1999/XSL/Transform" xmlns:ns4="dummy.com/xsd/naku_001">
<xsl:strip-space elements="ns4:TrackAndTrace"/>
<xsl:strip-space elements="ns4:Request"/> 
   <xsl:template match="@*|node()">
       <xsl:copy>
           <xsl:apply-templates select="@*|node()"/>
       </xsl:copy>
   </xsl:template>
</xsl:stylesheet> 
XSLT namespace and default namespace issue

XSLT namespace and default namespace issue


By : user5082540
Date : March 29 2020, 07:55 AM
should help you out Do you really need all that code? Or are you just using this as an incantation, in the hope it will somehow appease the evil spirits? Like what does xpath-default-namespace do in an XSLT 1.0 stylesheet? (Answer: either nothing, or produce a fatal error - depending on how tolerant your processor is).
Now, if your XML example is representative, then all you need to do is:
Related Posts Related Posts :
  • Ignore whitespace in Xtext rule
  • ServiceStack Ormlite: Circular reference between parent and child tables prevents foreign key creation
  • Can't connect to MobileFirst 7.1 server
  • See parameters that are overridden from TeamCity template
  • Can we send collection of messages in QuickBlox using Android SDK
  • SqlFileStream: Returning stream vs byte array in HTTP response
  • tvos: How should we handle low resolution monitor? like 1366x768
  • Aggregation binding only shows last item
  • Gitlab CI artifacts crashes with 403
  • InvalidSessionDescriptionError: Invalid description, no ice-ufrag attribute
  • Missing ionic.project file
  • ispConfig soap client functions of billing module does not exist
  • How to check for dynamic element names in a typeswitch expression?
  • braintree payments integration with zf2( zend framework 2 )
  • Sitecore 8 Admin role: Lock access
  • freemarker looping sequence error
  • How to set multiple commands in one yaml file with Kubernetes?
  • Quartz composer - output specific number
  • make gdb load a shared library from a specific path
  • ADD A COLUMN WITH SR.NO in Sap.m.table irrespective of other columns
  • Can I use SPARQL to query DBPedia for information about Wiki pages such as page length or number of times an article was
  • Jaro Similarity
  • How can I share sessions between Chrome and Paw?
  • how to start developing with OpenText CASE360
  • How to find relation between send and received message in twillio
  • Solve ~(P /\ Q) |- Q -> ~P in Isabelle
  • JetBrains Resharper 9 Ultimate Test Runner error: NUnit.Core.UnsupportedFrameworkException: Skipped loading assembly {My
  • Which RFID and RFID Reader to use?
  • wmi call returning Unexpected COM Error error
  • Training model ignored by stanford CoreNLP
  • z3: Is it possible to adjust the branching heuristics in Z3?
  • SAPUI5_JSON Data binding issue
  • Why does my protractor test have "no specs found" when I include jasmine-reporters in my config file?
  • How to remove "OK" button from Dialog fragment in Android
  • MobileFirst 7.1 connectOnStartup & WL.Client.connect different
  • OrientDB Fetch Plan/Strategies with Tinkerpop
  • Release memory from ID3D11Device::CreateBuffer(...)
  • Samsung SDK: how to install app through apache server and view logs in console?
  • Silex - Redirecting to home page if url not found
  • Convert a TIME8. to a Character Without First Converting to Numeric Format
  • ImageMagick, Can ImageMagick return single annotation as a bitmap?
  • Block access to some LAN ip`s using PFsense
  • noVNC Multiple Localhost Servers
  • What casts are allowed with `as`?
  • Google Drive API append file?
  • nix-env -qa not showing latest packages
  • In TI-BASIC, how do I add a variable in the middle of a String?
  • NetBeans - Display .gitignore Files in Projects/Files
  • Why is my command prompt freezing on Windows 10?
  • pass python arguments with argument name
  • Storing a time stamp(Calendar object) with objectify
  • Spark: join key-tuple pairs into key-list value
  • RethinkDB: Get last N from an object
  • How to direct my index to MediaWiki index.php
  • Removing ExecControl to upgrade to Ratpack v1.1.1?
  • When registering a table using the %pyspark interpreter in Zeppelin, I can't access the table in %sql
  • Phaser Sprite for joint between two bodies
  • The system detected a protection exception
  • OpenCL cannot find GPU device: NVIDIA GPU (Quadro K4000) + Visual Studio 2015
  • Rendr add custom header to fetch request (such as basic auth)
  • shadow
    Privacy Policy - Terms - Contact Us © animezone.co