XSLT problem with output when meet an IF condition
I can't handle with the following issue. I want to use an XSLT to transform an import xml in the needed format for the extension I am using. I want to set a specific value for a parameter when it met a specific IF condition.
This is the input xml:
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item><InStock>In Stock</InStock></item>
<item><InStock>Out of Stock</InStock></item>
</items>
This is what I am trying to use:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:g="http://base.google.com/ns/1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="product">
<xsl:element name="Items">
<xsl:for-each select="item">
<xsl:element name="Item">
<xsl:element name="quantity_and_stock_status">
<xsl:if test="InStock = 'In Stock'">
1
</xsl:if>
<xsl:if test="InStock = 'Out of Stock'">
0
</xsl:if>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
xml xslt
add a comment |
I can't handle with the following issue. I want to use an XSLT to transform an import xml in the needed format for the extension I am using. I want to set a specific value for a parameter when it met a specific IF condition.
This is the input xml:
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item><InStock>In Stock</InStock></item>
<item><InStock>Out of Stock</InStock></item>
</items>
This is what I am trying to use:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:g="http://base.google.com/ns/1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="product">
<xsl:element name="Items">
<xsl:for-each select="item">
<xsl:element name="Item">
<xsl:element name="quantity_and_stock_status">
<xsl:if test="InStock = 'In Stock'">
1
</xsl:if>
<xsl:if test="InStock = 'Out of Stock'">
0
</xsl:if>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
xml xslt
You have a template matchingproduct
, but there is no such element in your XML. Did you mean to matchitems
here?
– Tim C
Nov 14 '18 at 11:36
The type of the template is choosing on the previous step in the extension, then it comes the XSLT transformation based on the previous choice.
– lyuben.yurukov
Nov 14 '18 at 12:20
You may need to explain more about this extension. At the moment, all that can be said that the XSLT will not apply to your XML, as the XSLT is looking to matchproduct
which is not in your XML. It might help if you also said what output you are currently getting, and what you expect. Thank you!
– Tim C
Nov 14 '18 at 13:43
You haven't asked a question. You've said what you're doing (good!) but you haven't said what output you want to produce and how your current code fails.
– Michael Kay
Nov 14 '18 at 15:04
XML is case sensitive, you are using "Item" and "item" as if they were interchangeable.
– Michael Kay
Nov 14 '18 at 15:05
add a comment |
I can't handle with the following issue. I want to use an XSLT to transform an import xml in the needed format for the extension I am using. I want to set a specific value for a parameter when it met a specific IF condition.
This is the input xml:
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item><InStock>In Stock</InStock></item>
<item><InStock>Out of Stock</InStock></item>
</items>
This is what I am trying to use:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:g="http://base.google.com/ns/1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="product">
<xsl:element name="Items">
<xsl:for-each select="item">
<xsl:element name="Item">
<xsl:element name="quantity_and_stock_status">
<xsl:if test="InStock = 'In Stock'">
1
</xsl:if>
<xsl:if test="InStock = 'Out of Stock'">
0
</xsl:if>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
xml xslt
I can't handle with the following issue. I want to use an XSLT to transform an import xml in the needed format for the extension I am using. I want to set a specific value for a parameter when it met a specific IF condition.
This is the input xml:
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item><InStock>In Stock</InStock></item>
<item><InStock>Out of Stock</InStock></item>
</items>
This is what I am trying to use:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:g="http://base.google.com/ns/1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="product">
<xsl:element name="Items">
<xsl:for-each select="item">
<xsl:element name="Item">
<xsl:element name="quantity_and_stock_status">
<xsl:if test="InStock = 'In Stock'">
1
</xsl:if>
<xsl:if test="InStock = 'Out of Stock'">
0
</xsl:if>
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
xml xslt
xml xslt
asked Nov 14 '18 at 11:22
lyuben.yurukovlyuben.yurukov
1
1
You have a template matchingproduct
, but there is no such element in your XML. Did you mean to matchitems
here?
– Tim C
Nov 14 '18 at 11:36
The type of the template is choosing on the previous step in the extension, then it comes the XSLT transformation based on the previous choice.
– lyuben.yurukov
Nov 14 '18 at 12:20
You may need to explain more about this extension. At the moment, all that can be said that the XSLT will not apply to your XML, as the XSLT is looking to matchproduct
which is not in your XML. It might help if you also said what output you are currently getting, and what you expect. Thank you!
– Tim C
Nov 14 '18 at 13:43
You haven't asked a question. You've said what you're doing (good!) but you haven't said what output you want to produce and how your current code fails.
– Michael Kay
Nov 14 '18 at 15:04
XML is case sensitive, you are using "Item" and "item" as if they were interchangeable.
– Michael Kay
Nov 14 '18 at 15:05
add a comment |
You have a template matchingproduct
, but there is no such element in your XML. Did you mean to matchitems
here?
– Tim C
Nov 14 '18 at 11:36
The type of the template is choosing on the previous step in the extension, then it comes the XSLT transformation based on the previous choice.
– lyuben.yurukov
Nov 14 '18 at 12:20
You may need to explain more about this extension. At the moment, all that can be said that the XSLT will not apply to your XML, as the XSLT is looking to matchproduct
which is not in your XML. It might help if you also said what output you are currently getting, and what you expect. Thank you!
– Tim C
Nov 14 '18 at 13:43
You haven't asked a question. You've said what you're doing (good!) but you haven't said what output you want to produce and how your current code fails.
– Michael Kay
Nov 14 '18 at 15:04
XML is case sensitive, you are using "Item" and "item" as if they were interchangeable.
– Michael Kay
Nov 14 '18 at 15:05
You have a template matching
product
, but there is no such element in your XML. Did you mean to match items
here?– Tim C
Nov 14 '18 at 11:36
You have a template matching
product
, but there is no such element in your XML. Did you mean to match items
here?– Tim C
Nov 14 '18 at 11:36
The type of the template is choosing on the previous step in the extension, then it comes the XSLT transformation based on the previous choice.
– lyuben.yurukov
Nov 14 '18 at 12:20
The type of the template is choosing on the previous step in the extension, then it comes the XSLT transformation based on the previous choice.
– lyuben.yurukov
Nov 14 '18 at 12:20
You may need to explain more about this extension. At the moment, all that can be said that the XSLT will not apply to your XML, as the XSLT is looking to match
product
which is not in your XML. It might help if you also said what output you are currently getting, and what you expect. Thank you!– Tim C
Nov 14 '18 at 13:43
You may need to explain more about this extension. At the moment, all that can be said that the XSLT will not apply to your XML, as the XSLT is looking to match
product
which is not in your XML. It might help if you also said what output you are currently getting, and what you expect. Thank you!– Tim C
Nov 14 '18 at 13:43
You haven't asked a question. You've said what you're doing (good!) but you haven't said what output you want to produce and how your current code fails.
– Michael Kay
Nov 14 '18 at 15:04
You haven't asked a question. You've said what you're doing (good!) but you haven't said what output you want to produce and how your current code fails.
– Michael Kay
Nov 14 '18 at 15:04
XML is case sensitive, you are using "Item" and "item" as if they were interchangeable.
– Michael Kay
Nov 14 '18 at 15:05
XML is case sensitive, you are using "Item" and "item" as if they were interchangeable.
– Michael Kay
Nov 14 '18 at 15:05
add a comment |
0
active
oldest
votes
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%2f53299061%2fxslt-problem-with-output-when-meet-an-if-condition%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53299061%2fxslt-problem-with-output-when-meet-an-if-condition%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 have a template matching
product
, but there is no such element in your XML. Did you mean to matchitems
here?– Tim C
Nov 14 '18 at 11:36
The type of the template is choosing on the previous step in the extension, then it comes the XSLT transformation based on the previous choice.
– lyuben.yurukov
Nov 14 '18 at 12:20
You may need to explain more about this extension. At the moment, all that can be said that the XSLT will not apply to your XML, as the XSLT is looking to match
product
which is not in your XML. It might help if you also said what output you are currently getting, and what you expect. Thank you!– Tim C
Nov 14 '18 at 13:43
You haven't asked a question. You've said what you're doing (good!) but you haven't said what output you want to produce and how your current code fails.
– Michael Kay
Nov 14 '18 at 15:04
XML is case sensitive, you are using "Item" and "item" as if they were interchangeable.
– Michael Kay
Nov 14 '18 at 15:05