XSLT - How to store a set of elements removed from source document for reuseHow can xsl:apply-templates match only templates I have defined?Transforming XML mixed nodes with disable-output-escapingIn what order do templates in an XSLT document execute, and do they match on the source XML or the buffered output?Select template for execution using a condition including variable on apply-templateshow to sort elements and group them based on unique element or ID, which has namespaceHow to Duplicate xml elementsXSLT - Adding attribute to element in separate templates?XSLT function exslt:object-type in IE and Chromeretrieve value of name attribute of all xsl:element and xsl:attribute tag from xslt document Using javavariable using in namespace definition
Where can I find a clear explanation (brief derivation) of N(d1) and N(d2)?
How do you pronounce "Hain"?
World of (nearly) identical snowflakes
Can a US President, after impeachment and removal, be re-elected or re-appointed?
Dual nationality and return to US the day the US Passport expires
How did the Axis intend to hold the Caucasus?
How can Paypal know my card is being used in another account?
Wand of the War Mage spellcasting focus and bonus interaction with multiclassing
Irreducible factors of primitive permutation group representation
Why force the nose of 737 Max down in the first place?
Are the named pipe created by `mknod` and the FIFO created by `mkfifo` equivalent?
Why isn't there any 9.5 digit multimeter or higher?
What container to use to store developer concentrate?
How likely is fragmentation on a table with 40000 products likely to affect performance
Summoning A Technology Based Demon
Why would anyone ever invest in a cash-only etf?
Do the books ever say oliphaunts aren’t elephants?
Do 3/8 (37.5%) of Quadratics Have No x-Intercepts?
Assuring luggage isn't lost with short layover
Why did some Apollo missions carry a grenade launcher?
Can I change the license of a forked project to the MIT if the license of the parent project has changed from the GPL to the MIT?
What are the closest international airports in different countries?
Composing fill in the blanks
Is it safe if the neutral lead is exposed and disconnected?
XSLT - How to store a set of elements removed from source document for reuse
How can xsl:apply-templates match only templates I have defined?Transforming XML mixed nodes with disable-output-escapingIn what order do templates in an XSLT document execute, and do they match on the source XML or the buffered output?Select template for execution using a condition including variable on apply-templateshow to sort elements and group them based on unique element or ID, which has namespaceHow to Duplicate xml elementsXSLT - Adding attribute to element in separate templates?XSLT function exslt:object-type in IE and Chromeretrieve value of name attribute of all xsl:element and xsl:attribute tag from xslt document Using javavariable using in namespace definition
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Given the following XML:
<root>
<group>
<e1>001</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
<group>
<e1>002</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
<group>
<e1>003</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
<group>
<e1>004</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
</root>
Note that the 'e2' elements within each 'group' element are all the same, and this is guaranteed in the source document.
I am trying to use XSLT to do the following steps:
- save a copy of the set of 'e2' elements,
- erase all 'group' elements,
- create a default set of group elements with the set of e2s inserted into it
The desired output would look like this:
<root>
<group>
<e1>default1</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
<group>
<e1>default2</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
</root>
The values of 'e1' in the source document are irrelevant, and the values of 'e2' in the output document are known ahead of time and static. It's only the 'e2' values that are dynamic and I need to make sure that they are all there.
I've used a pattern similar to this before when replacing all elements with some hard-coded values before hand:
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<!-- Empty Template eliminates all but first 'group' element. -->
<xsl:template match="//group[preceding::group]"></xsl:template>
<xsl:template match="//group">
<xsl:element name="group">
<e1>default1</e1>
<!-- e2 elements inserted here somehow? -->
</xsl:element>
<xsl:element name="group">
<e1>default2</e1>
<!-- e2 elements inserted here somehow? -->
</xsl:element>
</xsl:template>
I tried storing those elements to a variable, but nothing was inserted into output html:
<xsl:variable name="e2Elements" select="//group[1]/e2"></xsl:variable>
<xsl:template match="//group">
<xsl:element name="group">
<e1>default1</e1>
<xsl:copy-of select="$e2Elements" />
</xsl:element>
</xsl:template>
But am not sure how to get the e2 elements inserted into the values. I'm using SaxonHE9.8N and have access to exslt namespace and xslt2.0
xml xslt saxon
add a comment |
Given the following XML:
<root>
<group>
<e1>001</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
<group>
<e1>002</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
<group>
<e1>003</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
<group>
<e1>004</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
</root>
Note that the 'e2' elements within each 'group' element are all the same, and this is guaranteed in the source document.
I am trying to use XSLT to do the following steps:
- save a copy of the set of 'e2' elements,
- erase all 'group' elements,
- create a default set of group elements with the set of e2s inserted into it
The desired output would look like this:
<root>
<group>
<e1>default1</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
<group>
<e1>default2</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
</root>
The values of 'e1' in the source document are irrelevant, and the values of 'e2' in the output document are known ahead of time and static. It's only the 'e2' values that are dynamic and I need to make sure that they are all there.
I've used a pattern similar to this before when replacing all elements with some hard-coded values before hand:
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<!-- Empty Template eliminates all but first 'group' element. -->
<xsl:template match="//group[preceding::group]"></xsl:template>
<xsl:template match="//group">
<xsl:element name="group">
<e1>default1</e1>
<!-- e2 elements inserted here somehow? -->
</xsl:element>
<xsl:element name="group">
<e1>default2</e1>
<!-- e2 elements inserted here somehow? -->
</xsl:element>
</xsl:template>
I tried storing those elements to a variable, but nothing was inserted into output html:
<xsl:variable name="e2Elements" select="//group[1]/e2"></xsl:variable>
<xsl:template match="//group">
<xsl:element name="group">
<e1>default1</e1>
<xsl:copy-of select="$e2Elements" />
</xsl:element>
</xsl:template>
But am not sure how to get the e2 elements inserted into the values. I'm using SaxonHE9.8N and have access to exslt namespace and xslt2.0
xml xslt saxon
You mention e3 elements, is that a typo?
– Michael Kay
Mar 26 at 19:46
Yup, sorry. Edit done.
– Kevin Whiteside
Mar 27 at 16:39
add a comment |
Given the following XML:
<root>
<group>
<e1>001</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
<group>
<e1>002</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
<group>
<e1>003</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
<group>
<e1>004</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
</root>
Note that the 'e2' elements within each 'group' element are all the same, and this is guaranteed in the source document.
I am trying to use XSLT to do the following steps:
- save a copy of the set of 'e2' elements,
- erase all 'group' elements,
- create a default set of group elements with the set of e2s inserted into it
The desired output would look like this:
<root>
<group>
<e1>default1</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
<group>
<e1>default2</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
</root>
The values of 'e1' in the source document are irrelevant, and the values of 'e2' in the output document are known ahead of time and static. It's only the 'e2' values that are dynamic and I need to make sure that they are all there.
I've used a pattern similar to this before when replacing all elements with some hard-coded values before hand:
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<!-- Empty Template eliminates all but first 'group' element. -->
<xsl:template match="//group[preceding::group]"></xsl:template>
<xsl:template match="//group">
<xsl:element name="group">
<e1>default1</e1>
<!-- e2 elements inserted here somehow? -->
</xsl:element>
<xsl:element name="group">
<e1>default2</e1>
<!-- e2 elements inserted here somehow? -->
</xsl:element>
</xsl:template>
I tried storing those elements to a variable, but nothing was inserted into output html:
<xsl:variable name="e2Elements" select="//group[1]/e2"></xsl:variable>
<xsl:template match="//group">
<xsl:element name="group">
<e1>default1</e1>
<xsl:copy-of select="$e2Elements" />
</xsl:element>
</xsl:template>
But am not sure how to get the e2 elements inserted into the values. I'm using SaxonHE9.8N and have access to exslt namespace and xslt2.0
xml xslt saxon
Given the following XML:
<root>
<group>
<e1>001</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
<group>
<e1>002</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
<group>
<e1>003</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
<group>
<e1>004</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
</root>
Note that the 'e2' elements within each 'group' element are all the same, and this is guaranteed in the source document.
I am trying to use XSLT to do the following steps:
- save a copy of the set of 'e2' elements,
- erase all 'group' elements,
- create a default set of group elements with the set of e2s inserted into it
The desired output would look like this:
<root>
<group>
<e1>default1</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
<group>
<e1>default2</e1>
<e2>beep</e2>
<e2>bop</e2>
<e2>ork</e2>
<e2>ah</e2>
<e2>ah</e2>
</group>
</root>
The values of 'e1' in the source document are irrelevant, and the values of 'e2' in the output document are known ahead of time and static. It's only the 'e2' values that are dynamic and I need to make sure that they are all there.
I've used a pattern similar to this before when replacing all elements with some hard-coded values before hand:
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<!-- Empty Template eliminates all but first 'group' element. -->
<xsl:template match="//group[preceding::group]"></xsl:template>
<xsl:template match="//group">
<xsl:element name="group">
<e1>default1</e1>
<!-- e2 elements inserted here somehow? -->
</xsl:element>
<xsl:element name="group">
<e1>default2</e1>
<!-- e2 elements inserted here somehow? -->
</xsl:element>
</xsl:template>
I tried storing those elements to a variable, but nothing was inserted into output html:
<xsl:variable name="e2Elements" select="//group[1]/e2"></xsl:variable>
<xsl:template match="//group">
<xsl:element name="group">
<e1>default1</e1>
<xsl:copy-of select="$e2Elements" />
</xsl:element>
</xsl:template>
But am not sure how to get the e2 elements inserted into the values. I'm using SaxonHE9.8N and have access to exslt namespace and xslt2.0
xml xslt saxon
xml xslt saxon
edited Mar 27 at 16:40
Kevin Whiteside
asked Mar 26 at 17:57
Kevin WhitesideKevin Whiteside
166 bronze badges
166 bronze badges
You mention e3 elements, is that a typo?
– Michael Kay
Mar 26 at 19:46
Yup, sorry. Edit done.
– Kevin Whiteside
Mar 27 at 16:39
add a comment |
You mention e3 elements, is that a typo?
– Michael Kay
Mar 26 at 19:46
Yup, sorry. Edit done.
– Kevin Whiteside
Mar 27 at 16:39
You mention e3 elements, is that a typo?
– Michael Kay
Mar 26 at 19:46
You mention e3 elements, is that a typo?
– Michael Kay
Mar 26 at 19:46
Yup, sorry. Edit done.
– Kevin Whiteside
Mar 27 at 16:39
Yup, sorry. Edit done.
– Kevin Whiteside
Mar 27 at 16:39
add a comment |
2 Answers
2
active
oldest
votes
Your solution is actually making an unnecessary copy of the elements. You can do it without copying them, like this:
<xsl:variable name="e3Elements" select="//group[1]/e2" />
Another inefficiency is the <xsl:template match="group[preceding::group]"/>
Using the preceding axis is always expensive, but especially so in a pattern. The obvious improvement is to replace it with preceding-sibling (searching the preceding-sibling axis is much faster than searching the preceding axis). But in fact you can do better than this: make this the default rule for groups (<xsl:template match="group"/>
), and make the other rule only match the first group (<xsl:template match="group[1]">...
).
But actually, there's no need to match the first group element either, because you're not using any of its data.
On a stylistic point, <group>
is to be preferred over <xsl:element name="group">
simply because it's much more readable.
This would be my XSLT 3.0 solution:
<xsl:transform version="3.0" .... expand-text="yes">
<xsl:template match="/">
<xsl:variable name="e3Elements" select="//group[1]/e2"/>
<xsl:for-each select="'default1', 'default2'">
<group>
<e1>.</e1>
<xsl:copy-of select="$e3Elements"/>
</group>
</xsl:for-each>
</xsl:template>
</xsl:transform>
As a note, I use xsl:element because it allowed me to specify a namespace so that the generated elements don't have xmlns:xxx attributes. The actual code I'm working with is super-heavily namespaced.
– Kevin Whiteside
Mar 27 at 16:51
add a comment |
Wound up that I needed to make my variable a copy of the element using copy-of. Below is my solution:
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:variable name="e3Elements">
<xsl:copy-of select="//group[1]/e2" />
</xsl:variable>
<xsl:template match="group[preceding::group]"></xsl:template>
<xsl:template match="group">
<xsl:element name="group">
<xsl:element name="e1">default1</xsl:element>
<xsl:copy-of select="$e3Elements"></xsl:copy-of>
</xsl:element>
<xsl:element name="group">
<xsl:element name="e1">default2</xsl:element>
<xsl:copy-of select="$e3Elements"></xsl:copy-of>
</xsl:element>
</xsl:template>
1
You don't need to usexsl:copy-of
in your variable. You can actually declare it as<xsl:variable name="e3Elements" select="//group[1]/e2" />
.
– Tim C
Mar 26 at 19:54
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55363510%2fxslt-how-to-store-a-set-of-elements-removed-from-source-document-for-reuse%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your solution is actually making an unnecessary copy of the elements. You can do it without copying them, like this:
<xsl:variable name="e3Elements" select="//group[1]/e2" />
Another inefficiency is the <xsl:template match="group[preceding::group]"/>
Using the preceding axis is always expensive, but especially so in a pattern. The obvious improvement is to replace it with preceding-sibling (searching the preceding-sibling axis is much faster than searching the preceding axis). But in fact you can do better than this: make this the default rule for groups (<xsl:template match="group"/>
), and make the other rule only match the first group (<xsl:template match="group[1]">...
).
But actually, there's no need to match the first group element either, because you're not using any of its data.
On a stylistic point, <group>
is to be preferred over <xsl:element name="group">
simply because it's much more readable.
This would be my XSLT 3.0 solution:
<xsl:transform version="3.0" .... expand-text="yes">
<xsl:template match="/">
<xsl:variable name="e3Elements" select="//group[1]/e2"/>
<xsl:for-each select="'default1', 'default2'">
<group>
<e1>.</e1>
<xsl:copy-of select="$e3Elements"/>
</group>
</xsl:for-each>
</xsl:template>
</xsl:transform>
As a note, I use xsl:element because it allowed me to specify a namespace so that the generated elements don't have xmlns:xxx attributes. The actual code I'm working with is super-heavily namespaced.
– Kevin Whiteside
Mar 27 at 16:51
add a comment |
Your solution is actually making an unnecessary copy of the elements. You can do it without copying them, like this:
<xsl:variable name="e3Elements" select="//group[1]/e2" />
Another inefficiency is the <xsl:template match="group[preceding::group]"/>
Using the preceding axis is always expensive, but especially so in a pattern. The obvious improvement is to replace it with preceding-sibling (searching the preceding-sibling axis is much faster than searching the preceding axis). But in fact you can do better than this: make this the default rule for groups (<xsl:template match="group"/>
), and make the other rule only match the first group (<xsl:template match="group[1]">...
).
But actually, there's no need to match the first group element either, because you're not using any of its data.
On a stylistic point, <group>
is to be preferred over <xsl:element name="group">
simply because it's much more readable.
This would be my XSLT 3.0 solution:
<xsl:transform version="3.0" .... expand-text="yes">
<xsl:template match="/">
<xsl:variable name="e3Elements" select="//group[1]/e2"/>
<xsl:for-each select="'default1', 'default2'">
<group>
<e1>.</e1>
<xsl:copy-of select="$e3Elements"/>
</group>
</xsl:for-each>
</xsl:template>
</xsl:transform>
As a note, I use xsl:element because it allowed me to specify a namespace so that the generated elements don't have xmlns:xxx attributes. The actual code I'm working with is super-heavily namespaced.
– Kevin Whiteside
Mar 27 at 16:51
add a comment |
Your solution is actually making an unnecessary copy of the elements. You can do it without copying them, like this:
<xsl:variable name="e3Elements" select="//group[1]/e2" />
Another inefficiency is the <xsl:template match="group[preceding::group]"/>
Using the preceding axis is always expensive, but especially so in a pattern. The obvious improvement is to replace it with preceding-sibling (searching the preceding-sibling axis is much faster than searching the preceding axis). But in fact you can do better than this: make this the default rule for groups (<xsl:template match="group"/>
), and make the other rule only match the first group (<xsl:template match="group[1]">...
).
But actually, there's no need to match the first group element either, because you're not using any of its data.
On a stylistic point, <group>
is to be preferred over <xsl:element name="group">
simply because it's much more readable.
This would be my XSLT 3.0 solution:
<xsl:transform version="3.0" .... expand-text="yes">
<xsl:template match="/">
<xsl:variable name="e3Elements" select="//group[1]/e2"/>
<xsl:for-each select="'default1', 'default2'">
<group>
<e1>.</e1>
<xsl:copy-of select="$e3Elements"/>
</group>
</xsl:for-each>
</xsl:template>
</xsl:transform>
Your solution is actually making an unnecessary copy of the elements. You can do it without copying them, like this:
<xsl:variable name="e3Elements" select="//group[1]/e2" />
Another inefficiency is the <xsl:template match="group[preceding::group]"/>
Using the preceding axis is always expensive, but especially so in a pattern. The obvious improvement is to replace it with preceding-sibling (searching the preceding-sibling axis is much faster than searching the preceding axis). But in fact you can do better than this: make this the default rule for groups (<xsl:template match="group"/>
), and make the other rule only match the first group (<xsl:template match="group[1]">...
).
But actually, there's no need to match the first group element either, because you're not using any of its data.
On a stylistic point, <group>
is to be preferred over <xsl:element name="group">
simply because it's much more readable.
This would be my XSLT 3.0 solution:
<xsl:transform version="3.0" .... expand-text="yes">
<xsl:template match="/">
<xsl:variable name="e3Elements" select="//group[1]/e2"/>
<xsl:for-each select="'default1', 'default2'">
<group>
<e1>.</e1>
<xsl:copy-of select="$e3Elements"/>
</group>
</xsl:for-each>
</xsl:template>
</xsl:transform>
answered Mar 26 at 19:59
Michael KayMichael Kay
116k6 gold badges64 silver badges123 bronze badges
116k6 gold badges64 silver badges123 bronze badges
As a note, I use xsl:element because it allowed me to specify a namespace so that the generated elements don't have xmlns:xxx attributes. The actual code I'm working with is super-heavily namespaced.
– Kevin Whiteside
Mar 27 at 16:51
add a comment |
As a note, I use xsl:element because it allowed me to specify a namespace so that the generated elements don't have xmlns:xxx attributes. The actual code I'm working with is super-heavily namespaced.
– Kevin Whiteside
Mar 27 at 16:51
As a note, I use xsl:element because it allowed me to specify a namespace so that the generated elements don't have xmlns:xxx attributes. The actual code I'm working with is super-heavily namespaced.
– Kevin Whiteside
Mar 27 at 16:51
As a note, I use xsl:element because it allowed me to specify a namespace so that the generated elements don't have xmlns:xxx attributes. The actual code I'm working with is super-heavily namespaced.
– Kevin Whiteside
Mar 27 at 16:51
add a comment |
Wound up that I needed to make my variable a copy of the element using copy-of. Below is my solution:
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:variable name="e3Elements">
<xsl:copy-of select="//group[1]/e2" />
</xsl:variable>
<xsl:template match="group[preceding::group]"></xsl:template>
<xsl:template match="group">
<xsl:element name="group">
<xsl:element name="e1">default1</xsl:element>
<xsl:copy-of select="$e3Elements"></xsl:copy-of>
</xsl:element>
<xsl:element name="group">
<xsl:element name="e1">default2</xsl:element>
<xsl:copy-of select="$e3Elements"></xsl:copy-of>
</xsl:element>
</xsl:template>
1
You don't need to usexsl:copy-of
in your variable. You can actually declare it as<xsl:variable name="e3Elements" select="//group[1]/e2" />
.
– Tim C
Mar 26 at 19:54
add a comment |
Wound up that I needed to make my variable a copy of the element using copy-of. Below is my solution:
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:variable name="e3Elements">
<xsl:copy-of select="//group[1]/e2" />
</xsl:variable>
<xsl:template match="group[preceding::group]"></xsl:template>
<xsl:template match="group">
<xsl:element name="group">
<xsl:element name="e1">default1</xsl:element>
<xsl:copy-of select="$e3Elements"></xsl:copy-of>
</xsl:element>
<xsl:element name="group">
<xsl:element name="e1">default2</xsl:element>
<xsl:copy-of select="$e3Elements"></xsl:copy-of>
</xsl:element>
</xsl:template>
1
You don't need to usexsl:copy-of
in your variable. You can actually declare it as<xsl:variable name="e3Elements" select="//group[1]/e2" />
.
– Tim C
Mar 26 at 19:54
add a comment |
Wound up that I needed to make my variable a copy of the element using copy-of. Below is my solution:
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:variable name="e3Elements">
<xsl:copy-of select="//group[1]/e2" />
</xsl:variable>
<xsl:template match="group[preceding::group]"></xsl:template>
<xsl:template match="group">
<xsl:element name="group">
<xsl:element name="e1">default1</xsl:element>
<xsl:copy-of select="$e3Elements"></xsl:copy-of>
</xsl:element>
<xsl:element name="group">
<xsl:element name="e1">default2</xsl:element>
<xsl:copy-of select="$e3Elements"></xsl:copy-of>
</xsl:element>
</xsl:template>
Wound up that I needed to make my variable a copy of the element using copy-of. Below is my solution:
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>
<xsl:variable name="e3Elements">
<xsl:copy-of select="//group[1]/e2" />
</xsl:variable>
<xsl:template match="group[preceding::group]"></xsl:template>
<xsl:template match="group">
<xsl:element name="group">
<xsl:element name="e1">default1</xsl:element>
<xsl:copy-of select="$e3Elements"></xsl:copy-of>
</xsl:element>
<xsl:element name="group">
<xsl:element name="e1">default2</xsl:element>
<xsl:copy-of select="$e3Elements"></xsl:copy-of>
</xsl:element>
</xsl:template>
answered Mar 26 at 19:32
Kevin WhitesideKevin Whiteside
166 bronze badges
166 bronze badges
1
You don't need to usexsl:copy-of
in your variable. You can actually declare it as<xsl:variable name="e3Elements" select="//group[1]/e2" />
.
– Tim C
Mar 26 at 19:54
add a comment |
1
You don't need to usexsl:copy-of
in your variable. You can actually declare it as<xsl:variable name="e3Elements" select="//group[1]/e2" />
.
– Tim C
Mar 26 at 19:54
1
1
You don't need to use
xsl:copy-of
in your variable. You can actually declare it as <xsl:variable name="e3Elements" select="//group[1]/e2" />
.– Tim C
Mar 26 at 19:54
You don't need to use
xsl:copy-of
in your variable. You can actually declare it as <xsl:variable name="e3Elements" select="//group[1]/e2" />
.– Tim C
Mar 26 at 19:54
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55363510%2fxslt-how-to-store-a-set-of-elements-removed-from-source-document-for-reuse%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You mention e3 elements, is that a typo?
– Michael Kay
Mar 26 at 19:46
Yup, sorry. Edit done.
– Kevin Whiteside
Mar 27 at 16:39