trygves
asked on
xsl1.0: xml node name based on value in other tag
Hello, in incoming xml I have total amount value; if value is gt 0; the document is invoice; if it is lt 0; it is credit invoice.
The outgoing xml needs different names on tags if invoice or credit note.
I tried like this; but get
"Expected white space"
when running in Stylus:
<xsl:variable name="MAINHEADER">
<xsl:choose>
<xsl:when test="INVOIC/OrderHead/Ord _4182 < 0">
<xsl:value-of select="'<CreditNote xmlns=""urn:oasis:names:sp ecificatio n:ubl:sche ma:xsd:Cre ditNote-2" " xmlns:cac=""urn:oasis:name s:specific ation:ubl: schema:xsd :CommonAgg regateComp onents-2"" xmlns:cbc=""urn:oasis:name s:specific ation:ubl: schema:xsd :CommonBas icComponen ts-2"" xmlns:ccts=""urn:un:unece: uncefact:d ocumentati on:2"" xmlns:ext=""urn:oasis:name s:specific ation:ubl: schema:xsd :CommonExt ensionComp onents-2"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">'"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'<inv:Invoice xmlns:inv=""urn:oasis:name s:specific ation:ubl: schema:xsd :Invoice-2 "" xmlns:ext=""urn:oasis:name s:specific ation:ubl: schema:xsd :CommonExt ensionComp onents-2"" xmlns:cbc=""urn:oasis:name s:specific ation:ubl: schema:xsd :CommonBas icComponen ts-2"" xmlns:cac=""urn:oasis:name s:specific ation:ubl: schema:xsd :CommonAgg regateComp onents-2"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
Error message says whitespace should be here (marked bold):
<xsl:value-of select="'<CreditNote
What am I missing?
The outgoing xml needs different names on tags if invoice or credit note.
I tried like this; but get
"Expected white space"
when running in Stylus:
<xsl:variable name="MAINHEADER">
<xsl:choose>
<xsl:when test="INVOIC/OrderHead/Ord
<xsl:value-of select="'<CreditNote xmlns=""urn:oasis:names:sp
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'<inv:Invoice xmlns:inv=""urn:oasis:name
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
Error message says whitespace should be here (marked bold):
<xsl:value-of select="'<CreditNote
What am I missing?
Can you put an example XML and your full XSLT?
Then I could show you how you can do this
Put the choose on the top level (don't use a variable) and do an apply-templates for the other nodes from within the choose
Here is how I would get started with this
Then I could show you how you can do this
Put the choose on the top level (don't use a variable) and do an apply-templates for the other nodes from within the choose
Here is how I would get started with 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:template match="/">
<xsl:choose>
<xsl:when test="INVOIC/OrderHead/Ord_4182 < 0">
<CreditNote xmlns="urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ccts="urn:un:unece:uncefact:documentation:2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:apply-templates/>
</CreditNote>
</xsl:when>
<xsl:otherwise>
<inv:Invoice xmlns:inv="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:apply-templates/>
</inv:Invoice>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
</xsl:template>
<!-- templates for child elements go here -->
</xsl:stylesheet>
ASKER
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You need to put down the <inv:Invoice in literal nodes
It is pretty hard to do so in a variable
but you can put the elemant name in a variable and use xsl:element