Generating dynamic xmlns
I would like to dynamically generate xmlns attributes.
I want to generate this in XSL:
<Common: MainPageBase xmlns: Common = "clr-namespace: ThisPartIsDynamic ; assembly = ThisPartIsDynamic "> </ General: MainPageBase>
How can I do this in XSL?
Thanks, Alex
Update
To be more precise, this is what I need to create. The parts I want to change with variables is "THISPARTISDYNAMIC":
<Common:MainPageBase
xmlns:Common="clr-namespace:THISPARTISDYNAMIC;assembly=THISPARTISDYNAMIC"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:df="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"
xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
xmlns:uc="clr-namespace:THISPARTISDYNAMIC"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
></Common:MainPageBase>
Any ideas?
a source to share
This transformation :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:variable name="vDynamicPart1" select="'DynPArt1'"/>
<xsl:variable name="vDynamicPart2" select="'DynPArt2'"/>
<xsl:template match="/">
<xsl:element name="Common:MainPageBase"
namespace="clr-namespace:{$vDynamicPart1};assembly={$vDynamicPart2}"/>
</xsl:template>
</xsl:stylesheet>
when applied to any XML document (not used), gives the desired result .
a source to share
You can set the namespace of an element dynamically:
<param name="ns1" >http://localhost/ns1</param>
...
<xsl:element name="test" namespace="{$ns1}" >... </xsl:element>
But that doesn't output the namespace prefix - it changes the default namespace for that element.
I don't think there is a way to deduce the prefixes using the dynamic namespace URI. Something like: <xyz:test xmlns:xyz="{$ns1}">
outputs exactly this literally:<xyz:test xmlns:xyz="{$ns1}">
If this is really the exact result you want, then I think you either have to modify the serializer or just output the result using a placeholder URI and do the text replacement on the output XML text.
[XSLT does not process XML syntax. It processes XML trees. Parsing the input and serializing the output is out of scope. ]
a source to share
Take a look at the article Namespaces in XSLT , and in XSLT 1.0: Creating Dynamic Name Node Nodes in particular.
a source to share