Support #4960
closedXSLT 3 Transform namespace, root element and conditional attribute
Added by Anonymous over 3 years ago. Updated over 3 years ago.
0%
Description
Hello:
I am developing an XSLT 3 module to transform all of the namespaces, the root element and conditionally remove the child element's attributes.
Problem:
I can't manage to transform the root element from requestConfirmation
to requestProduct
.
Have tried other methods, either the xmlns="http://example/confirmation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
persistently presents itself in all of the subsequent elements with namespaces or root is not transformed.
What is the XSLT 3 solution?
Thanks!
Files
xslt3-beta-transform-ns&root.xsl (1.44 KB) xslt3-beta-transform-ns&root.xsl | XSLT3 Identity transform | Anonymous, 2021-04-02 06:45 | |
scaffold.xqy (455 Bytes) scaffold.xqy | Anonymous, 2021-04-03 05:47 | ||
xslt3-beta-transform-ns&root.xsl (1.52 KB) xslt3-beta-transform-ns&root.xsl | Anonymous, 2021-04-03 05:47 |
Updated by Martin Honnen over 3 years ago
To transform the root element, you obviously need a template matching it and then output the new one. For the other elements, one template suffices, for the attributes one XSLT 3 approach would be to use a static param in a shadow attribute:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="http://example/confirmation"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:param name="new-namespace" as="xs:string">http://fc.fasset/product</xsl:param>
<xsl:param name="keep-atts" static="yes" as="xs:string*" select="'href', 'id'"/>
<xsl:template match="/*">
<xsl:element name="requestProduct" namespace="{$new-namespace}">
<xsl:apply-templates select="@* , node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}" namespace="{$new-namespace}">
<xsl:apply-templates select="@* , node()"/>
</xsl:element>
</xsl:template>
<xsl:template _match="{string-join($keep-atts!('@' || .), ' | ')}"/>
<xsl:template match="@*"/>
</xsl:stylesheet>
I haven't quite understood whether you expect the attributes you want to keep to be sometimes in a namespace, the above assumes they are in no namespace.
Updated by Anonymous over 3 years ago
Cool…
For although I don’t particularly need to separate the keep-attr
namespace with the trans-namespace
, the emailed .xsl does so. I haven’t experimented XSLT 3 static param in a shadow attribute
to transform attributes with namespace. If you care to demonstrate…for sporting purpose.
Is it possible to translate the scaffold.xqy
into an xsl as a parameterized template (if you can call the .xqy from the main template, it is also good), similar to a preprocessing instruction.
e.g. the main template calls $scaffold:confirm[1]
which is an equivalent of $trans-root
, calls $scaffold:confirm[2]
which is an equivalent of $trans-namespace
…so on & forth…Any thought ?
Updated by Sam Spade (anonymousjuly1@yahoo.ca) over 3 years ago
- File scaffold.xqy scaffold.xqy added
- File xslt3-beta-transform-ns&root.xsl xslt3-beta-transform-ns&root.xsl added
- File euro-exotic-dba13-b1ecc301-8e53-4b93-9741-42988405e8a2.xml added
Hello:
Can you please help to remove the originalattached [euro-exotic-dba13-b1ecc301-8e53-4b93-9741-42988405e8a2.xml] and [xslt3-beta-remove-comment-change-ns&root.xml]? The mockup contained real brokeragefirm names. This new attached xml doesn’t.
I also just realise it will be a holiday weekend and I do not wish to spoil it…
Cheers,
Fiona
On Friday, April 2, 2021, 1:45:44 a.m. MST, Saxonica Developer Community notifications@plan.io wrote:
| Issue #4960 has been updated by Martin Honnen.
To transform the root element, you obviously need a template matching it and then output the new one. For the other elements, one template suffices, for the attributes one XSLT 3 approach would be to use a static param in a shadow attribute:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xpath-default-namespace="http://example/confirmation"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:param name="new-namespace" as="xs:string">http://fc.fasset/product</xsl:param>
<xsl:param name="keep-atts" static="yes" as="xs:string*" select="'href', 'id'"/>
<xsl:template match="/">
<xsl:element name="requestProduct" namespace="{$new-namespace}">
<xsl:apply-templates select="@ , node()"/>
</xsl:element>
</xsl:template>
<xsl:template match="">
<xsl:element name="{local-name()}" namespace="{$new-namespace}">
<xsl:apply-templates select="@ , node()"/>
</xsl:element>
</xsl:template>
<xsl:template _match="{string-join($keep-atts!('@' || .), ' | ')}"/>
<xsl:template match="@*"/>
</xsl:stylesheet>
I haven't quite understood whether you expect the attributes you want to keep to be sometimes in a namespace, the above assumes they are in no namespace.
Support #4960: XSLT 3 Transform namespace, root element and conditional attribute
- Author: Fiona Chen
- Status: New
- Priority: Low
- Assignee:
- Category:
- Sprint/Milestone:
- Legacy ID:
- Applies to branch: 9.9
- Fix Committed on Branch:
- Fixed in Maintenance Release:
Hello:I am developing an XSLT 3 module to transform all of the namespaces, the root element and conditionally remove the child element's attributes.Problem:I can't manage to transform the root element from requestConfirmation to requestProduct.
Have tried other methods, either the xmlns="http://example/confirmation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" persistently presents itself in all of the subsequent elements with namespaces or root is not transformed.
What is the XSLT 3 solution?
Thanks!
Files xslt3-beta-transform-ns&root.xsl (1.44 KB)
euro-exotic-dba13-b1ecc301-8e53-4b93-9741-42988405e8a2.xml (3.54 KB)
xslt3-beta-remove-comment-change-ns&root.xml (3.01 KB)
|
|
You have received this notification because you have either subscribed to or are involved in a project on Saxonica Developer Community site.To change your notification preferences, please click here: https://saxonica.plan.io/my/account?tour=mail_preferences
|
|
This notification was cheerfully delivered by |
| |
Updated by Michael Kay over 3 years ago
- File deleted (
euro-exotic-dba13-b1ecc301-8e53-4b93-9741-42988405e8a2.xml)
Updated by Michael Kay over 3 years ago
- File deleted (
euro-exotic-dba13-b1ecc301-8e53-4b93-9741-42988405e8a2.xml)
Updated by Norm Tovey-Walsh over 3 years ago
- File deleted (
xslt3-beta-remove-comment-change-ns&root.xml)
Updated by Michael Kay over 3 years ago
- Status changed from New to AwaitingInfo
Thanks Martin for responding to this. I haven't had time to check the answer but Martin is 100% reliable...
Unless we hear further from you, Fiona, we'll mark this as closed.
Updated by Michael Kay over 3 years ago
- Status changed from AwaitingInfo to Closed
Please register to edit this issue