Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I need to create a xml file with xslt. I need that the first element contains two attribute as followed:

<Nomination_Doc release="1"
xmlns="sas:nominate:1">

I tried the following code:

   <xsl:element name="Nomination_Doc">
   <xsl:attribute name="release">1</xsl:attribute>
   <xsl:attribute name="xmlns">sas:nominate:1</xsl:attribute>

but it gives me:

<Nomination_Doc release="1">

and the attribute xmlns is missing. i did a little research and found out that xmlns is like a reserved word, which is used only to declare a namespace SOURCE. What is the solution in this case?

question from:https://stackoverflow.com/questions/66065807/add-xmlns-as-an-attribute-to-an-element-in-xslt

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
382 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can and just should literally write

<Nomination_Doc release="1" xmlns="sas:nominate:1">

in XSLT if you want to create an element whose name and namespace is known when writing the code. xsl:element is only needed when you want to compute the element name and/or namespace at run-time.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...