XML coding is given below
<math>
<mn>
<mphantom>12</mphantom>
</mn>
</math>
Output required:
<?xml version='1.0' encoding='UTF-8'?>
<math>|phantom1||phantom2|</math>
XSLT tried:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:m="http://www.w3.org/1998/Math/MathML"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cl="http://xml.cengage-learning.com/cendoc-core"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:xlink="http://www.w3.org/1999/xlink">
<xsl:output method="xml" encoding="UTF-8" indent="no" />
<xsl:strip-space elements="*" />
<xsl:template match="#* | node()">
<xsl:copy>
<xsl:apply-templates select="#* | node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="mn">
<xsl:variable name="pText" select="." />
<xsl:variable name="numst" select="2" />
<xsl:choose>
<xsl:when test="not(string-length($pText))>0">
<xsl:value-of select="$pText" />
</xsl:when>
<xsl:otherwise>
<xsl:variable name="ConcatStr" select="substring($pText,$numst)" />
<xsl:variable name="FinalStr" select="substring-before($pText,$ConcatStr)" />
<xsl:text disable-output-escaping="yes">|phantom</xsl:text>
<xsl:value-of select="$FinalStr" />
<xsl:text disable-output-escaping="yes">|</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="mphantom">
<xsl:apply-templates />
</xsl:template>
</xsl:stylesheet>
I used the above XSLT to transform but I am getting only the first number. But I need to use it as recursive. I am using XSLT 1.0. Kindly suggest
Here is a simpler, non-recursive solution, using the Piez method:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="mphantom">
<math>
<xsl:variable name="vCur" select="."/>
<xsl:for-each select=
"(document('')//node()|document('')//#*|document('')//namespace::*)
[not(position() > string-length($vCur))]
">
<xsl:value-of select="concat('|', substring($vCur, position(), 1),'|')"/>
</xsl:for-each>
</math>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied on the provided XML document:
<math>
<mn>
<mphantom>12</mphantom>
</mn>
</math>
the wanted, correct result is produced:
<math>|1||2|</math>
II. For completeness, here is an XSLT 2.0 solution:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="mphantom">
<math>
<xsl:value-of separator="" select=
"for $i in 1 to string-length()
return
concat('|', substring(., $i, 1), '|')
"/>
</math>
</xsl:template>
</xsl:stylesheet>
Try this..
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" omit-xml-declaration="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="mn[mphantom]" name="phant">
<xsl:param name="chars" select="mphantom" />
<xsl:value-of select="concat('|phantom',substring($chars,1,1),'|')" />
<xsl:if test="substring($chars,2)">
<xsl:call-template name="phant">
<xsl:with-param name="chars" select="substring($chars,2)" />
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Related
Experts, i need to write XSLT 1.0 code to eliminate the Pipe delimited symbol inside double quotes and also need to remove those double quotes..
Input:
<?xml version="1.0" encoding="utf-8"?>
<ns:MT_FILE>
<LN>
<LD>EXTRACT|"28|53"|1308026.7500|1176</LD>
</LN>
<LN>
<LD>DETAIL|1176|"LOS LE|OS PARRILLA"|Y|R||||<LD>
</LN>
</ns:MT_FILE>
** Desired Output:**
<?xml version="1.0" encoding="utf-8"?>
<ns:MT_FILE>
<LN>
<LD>EXTRACT|2853|1308026.7500|1176</LD>
</LN>
<LN>
<LD>DETAIL|1176|LOS LE OS PARRILLA|Y|R||||<LD>
</LN>
</ns:MT_FILE>
** XSLT I used is below:**
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*/text()">
<xsl:value-of select="translate(., '\"', '')"/>
</xsl:template>
</xsl:stylesheet>
This XSLT removing all the double quotes from my input field, please assist here..
If it can be assumed that quotes will always come in pairs, you could do:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<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="text()">
<xsl:call-template name="process">
<xsl:with-param name="text" select="."/>
</xsl:call-template>
</xsl:template>
<xsl:template name="process">
<xsl:param name="text"/>
<xsl:choose>
<xsl:when test="contains($text, '"')">
<xsl:value-of select="substring-before($text, '"')"/>
<xsl:value-of select="translate(substring-before(substring-after($text, '"'), '"'), '|', '')"/>
<xsl:call-template name="process">
<xsl:with-param name="text" select="substring-after(substring-after($text, '"'), '"')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
As you tagged as EXSLT:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:regexp="http://exslt.org/regular-expressions"
exclude-result-prefixes="regexp">
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="#*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="LD/text()">
<xsl:value-of select="regexp:replace(., '(")([^|]+)\|([^"]+)(")', 'g', '$2$3')"/>
</xsl:template>
</xsl:stylesheet>
I am new to xml and am trying to add in a link between two collections by inserting a Position() number which I have added into the StyleCollection. I now need to insert this as a StyleLink into the PackingLineCollection where the StyleNumber is equal to the StyleNumber in the StyleCollection. Can anybody point me in the right direction?
Here is the Input:
<Order>
<UniqueReferenceNumber>Order1234</UniqueReferenceNumber>
<StyleCollection>
<Style>
<StyleNumber>1234</StyleNumber>
<StyleType>
<Code>abc</Code>
</StyleType>
<LocationNumber></LocationNumber>
</Style>
<Style>
<StyleNumber>567</StyleNumber>
<StyleType>
<Code>xyz</Code>
</StyleType>
<LocationNumber></LocationNumber>
</Style>
</StyleCollection>
<SubOrderCollection>
<SubOrder>
<UniqueReferenceNumber>SubOrder1</UniqueReferenceNumber>
<PackingLineCollection>
<PackingLine>
<StyleNumber>1234</StyleNumber>
</PackingLine>
</PackingLineCollection>
</SubOrder>
<SubOrder>
<UniqueReferenceNumber>SubOrder2</UniqueReferenceNumber>
<PackingLineCollection>
<PackingLine>
<StyleNumber>xyz</StyleNumber>
</PackingLine>
</PackingLineCollection>
</SubOrder>
</SubOrderCollection>
</Order>
Here is the xslt:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" mlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:template match ="/">
<Order>
<Reference>
<xsl:value-of select="Order/UniqueReferenceNumber"/>
</Reference>
<StyleCollection>
<xsl:for-each select="Order/StyleCollection/Style">
<Style>
<StyleNumber>
<xsl:value-of select="StyleNumber"/>
</StyleNumber>
<LocationNumber><xsl:value-of select="position()"/>
</LocationNumber>
<StyleType>
<Code>
<xsl:value-of select="StyleType/Code"/>
</Code>
</StyleType>
</Style>
</xsl:for-each>
</StyleCollection>
<SubOrderCollection>
<xsl:for-each select="Order/SubOrderCollection/SubOrder">
<SubOrder>
<Reference><xsl:value-of select="UniqueReferenceNumber"/>
</Reference>
<PackingLineCollection>
<xsl:for-each select="PackingLineCollection/PackingLine">
<PackingLine>
<StyleNumber>
<xsl:value-of select="StyleNumber" />
</StyleNumber>
<StyleLink><xsl:value-of
Select="Order/StyleCollection/Style/LocationNumber"/></StyleLink>
</PackingLine>
</xsl:for-each>
</PackingLineCollection>
</SubOrder>
</xsl:for-each>
</SubOrderCollection>
</Order>
</xsl:template>
</xsl:stylesheet>
I have implemented it using a key and xsl:number as follows (in XSLT 3 but the key and xsl:number should work in XSLT 1 or 2 as well, you would need to replace the used <xsl:mode on-no-match="shallow-copy"/> with the identity transformation template):
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="3.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:key name="style-ref" match="StyleCollection/Style" use="StyleNumber"/>
<xsl:template match="Style/LocationNumber">
<xsl:copy>
<xsl:number from="StyleCollection" level="any"/>
</xsl:copy>
</xsl:template>
<xsl:template match="PackingLine/StyleNumber">
<xsl:next-match/>
<xsl:apply-templates select="key('style-ref', .)" mode="count"/>
</xsl:template>
<xsl:template match="Style" mode="count">
<StyleLink>
<xsl:number level="any" from="StyleCollection"/>
</StyleLink>
</xsl:template>
</xsl:stylesheet>
https://xsltfiddle.liberty-development.net/nc4NzQt/1 however does not find a matching Style for the second PackingLine/StyleNumber, not sure whether your example data is meant to have no reference there or whether I misunderstood your requirements.
XSLT 1 is
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:template match="#* | node()" name="identity">
<xsl:copy>
<xsl:apply-templates select="#* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:key name="style-ref" match="StyleCollection/Style" use="StyleNumber"/>
<xsl:template match="Style/LocationNumber">
<xsl:copy>
<xsl:number from="StyleCollection" level="any"/>
</xsl:copy>
</xsl:template>
<xsl:template match="PackingLine/StyleNumber">
<xsl:call-template name="identity"/>
<xsl:apply-templates select="key('style-ref', .)" mode="count"/>
</xsl:template>
<xsl:template match="Style" mode="count">
<StyleLink>
<xsl:number level="any" from="StyleCollection"/>
</StyleLink>
</xsl:template>
</xsl:stylesheet>
https://xsltfiddle.liberty-development.net/nc4NzQt/2
Consider following xml:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<base>
<a>
<b>
<c>Text 1</c>
</b>
</a>
</base>
<base>
<a>
<b>
<c>Text 2</c>
</b>
</a>
</base>
</root>
and this xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates select="root/base[1]" />
</xsl:template>
<xsl:template match="base//*">
<xsl:if test="text()">
<xsl:value-of select="text()" />
<!-- i need Text 2 here -->
</xsl:if>
<xsl:apply-templates />
</xsl:template>
<xsl:template match="text()" />
</xsl:stylesheet>
The original xml is much more nested an i don't know the exact structure. But there is a parallel node with the same structure. If my template is at //root/base[1]/a/b/c I want to reference //root/base[2]/a/b/c
However I only know that I am in some node below //root/base[1] and that there is the same node in //root/base[2].
Is there a possibility to accomplish this goal?
This stylesheet requires no extensions, and does not make any assumption on unique names; the boring part is to pass the correct "twin node" every time you call xsl:apply-templates:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates select="root/base[1]">
<xsl:with-param name="twin" select="root/base[2]"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="*">
<xsl:param name="twin"/>
<xsl:if test="text()">
<xsl:value-of select="text()" />
<xsl:value-of select="$twin/text()"/>
</xsl:if>
<xsl:for-each select="*">
<xsl:variable name="pos" select="position()"/>
<xsl:apply-templates select=".">
<xsl:with-param name="twin" select="$twin/*[$pos]"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>
<xsl:template match="text()" />
</xsl:stylesheet>
Solution with using saxon:evaluate extension (http://saxon.sourceforge.net/saxon7.9/extensions.html#evaluate)
You can also use dyn:evaluate if you are using xslt 1.0 processors (http://exslt.org/dyn/index.html):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
xmlns:saxon="http://saxon.sf.net/"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates select="root/base[1]" />
</xsl:template>
<xsl:template match="base//*">
<xsl:if test="text()">
<xsl:variable name="path">
<xsl:call-template name="constructPath">
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="rewritedPath" select="concat('/root/base[2]', substring($path, 11))"/>
<xsl:value-of select="text()" />
<xsl:value-of select="saxon:evaluate($rewritedPath)" />
</xsl:if>
<xsl:apply-templates />
</xsl:template>
<xsl:template name="constructPath">
<xsl:param name="node"/>
<xsl:choose>
<xsl:when test="$node/parent::node()/name()">
<xsl:call-template name="constructPath">
<xsl:with-param name="node" select="$node/parent::node()"/>
</xsl:call-template>
<xsl:value-of select="concat('/', $node/name())"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('/', $node/name())"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="text()" />
</xsl:stylesheet>
Here we use recursive template "constructPath" to create string and process it in evaluate() function. This will select the exact node as in the parallel branch. Hope this will help.
Try the code below. This code will work only if each base element has children with unique element name.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates select="root/base[1]" />
</xsl:template>
<xsl:template match="base//*">
<xsl:if test="text()">
<xsl:variable name="name" select="name()"/>
<xsl:value-of select="text()" />
<xsl:value-of select="ancestor::base/following-sibling::base[1]//*[name() = $name]" />
</xsl:if>
<xsl:apply-templates />
</xsl:template>
<xsl:template match="text()" />
However you can use dyn:evaluate from exslt extension or saxon:eval
Input XML is this:
<input>
<foo>John's bar</foo>
<bar>test</bar>
<foobar>testing</foobar>
</input>
After XSL transformation:
<input>
<foo>John's bar</foo>
<bar>this_test</bar>
</input>
But the legacy system expects:
<foo>John's bar</foo>
not <foo>John's bar</foo>
So I want to retain the value under <foo> as is rather than let XSLT parse it.
I tried using <xsl:output method="text"/> but with no luck of success..
I think XML itself when loaded gets parsed and XSLT just outputs as is..
If that's true I atleast want to escape it and make ' irrespective of whether it was &apose or ' in the input XML.
XSLT that I tried is this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="xml"/>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="bar">
<xsl:copy>
<xsl:text>this_</xsl:text>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="foobar"/>
</xsl:stylesheet>
If you are limited to XSLT 1.0, use disable-output-escaping="yes". This attribute can be used on xsl:text and xsl:value-of elements and it is deprecated in XSLT 2.0.
Stylesheet (XSLT 1.0)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:variable name="vApos">'</xsl:variable>
<xsl:variable name="vAmp">&</xsl:variable>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="bar">
<xsl:copy>
<xsl:text>this_</xsl:text>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="foobar"/>
<xsl:template match="foo">
<xsl:variable name="rep">
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="."/>
<xsl:with-param name="replace" select="$vApos" />
<xsl:with-param name="with" select="concat($vAmp,'apos;')"/>
</xsl:call-template>
</xsl:variable>
<xsl:copy>
<xsl:value-of select="$rep" disable-output-escaping="yes"/>
</xsl:copy>
</xsl:template>
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="with"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$with"/>
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="with" select="$with"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
The XSLT 1.0 solution makes use of advice given by Dimitre Novatchev here and Mads Hansen's answer here.
The XSLT 2.0 solution is more elegant, use a character-map to control the serialization of output. Make sure you escape the ampersand character as well (' instead of ').
Stylesheet (XSLT 2.0)
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" use-character-maps="apo"/>
<xsl:strip-space elements="*"/>
<xsl:character-map name="apo">
<xsl:output-character character="'" string="'"/>
</xsl:character-map>
<xsl:template match="#*|node()">
<xsl:copy>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="bar">
<xsl:copy>
<xsl:text>this_</xsl:text>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="foobar"/>
</xsl:stylesheet>
Output (Saxon 9.5 for 2.0, Xalan 2.7.1 for 1.0)
<?xml version="1.0" encoding="UTF-8"?>
<input>
<foo>John's bar</foo>
<bar>this_test</bar>
</input>
i got an xml-file with some elements. For some of these is an aqvivalent in a parameter xml-file along with some other elements.
I want to add these other elements from parm-file as parameter to output file if element-names are matching. (the Attributes should only be generated if an element "InvoiceHeader" exists in the source-xml.
Here is my code...
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:variable name="rpl" select="document('ParamInvoice.xml')"></xsl:variable>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates></xsl:apply-templates>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:if test="$rpl/StoraInvoice/local-name()">
<xsl:call-template name="AttributeErzeugen">
<xsl:with-param name="attr" select="$rpl/StoraInvoice/local-name()"></xsl:with-param>
</xsl:call-template>
</xsl:if>
<xsl:apply-templates></xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template name="AttributeErzeugen">
<xsl:param name="attr"></xsl:param>
<xsl:for-each select="$attr">
<xsl:attribute name="{Attibute/#name}"><xsl:value-of select="."></xsl:value- of></xsl:attribute>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
and here the param-file
<?xml version="1.0" encoding="UTF-8"?>
<StoraInvoice>
<InvoiceHeader>
<Attribute name="Fuehrend">YYY</Attribute>
<Attribute name="Feld">FFFF</Attribute>
<Attribute name="Format">XYZXYZ</Attribute>
</InvoiceHeader>
</StoraInvoice>
Siegfried
This transformation:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:my="my:my"
exclude-result-prefixes="my">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<my:rpl>
<StoraInvoice>
<t>
<InvoiceHeader>
<Attribute name="Fuehrend">YYY</Attribute>
<Attribute name="Feld">FFFF</Attribute>
<Attribute name="Format">XYZXYZ</Attribute>
</InvoiceHeader>
</t>
</StoraInvoice>
</my:rpl>
<xsl:variable name="rpl" select="document('')/*/my:rpl"/>
<xsl:template match="*">
<xsl:variable name="vInvoiceElement" select=
"$rpl/StoraInvoice/*[name()=name(current())]"/>
<xsl:copy>
<xsl:if test="$vInvoiceElement">
<xsl:call-template name="AttributeErzeugen">
<xsl:with-param name="pInvoiced" select="$vInvoiceElement"/>
</xsl:call-template>
</xsl:if>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template name="AttributeErzeugen">
<xsl:param name="pInvoiced"/>
<xsl:for-each select="$pInvoiced/InvoiceHeader/Attribute">
<xsl:attribute name="{#name}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
when applied on this XML document:
<t/>
produces the wanted, correct result:
<t Fuehrend="YYY" Feld="FFFF" Format="XYZXYZ"/>