XSLT Transform doesn't work until I remove root node












0















I'm trying to extract the headline from the below XML from the Met Office web service using XSLT, however my XSLT select returns blank.



SOURCE:



<RegionalFcst xmlns="www.metoffice.gov.uk/xml/metoRegionalFcst" createdOn="2016-01-13T02:14:39" issuedAt="2016-01-13T04:00:00" regionId="se">
<FcstPeriods>
<Period id="day1to2">
<Paragraph title="Headline:">Frosty start. Bright or sunny day.</Paragraph>
<Paragraph title="Today:">A clear and frosty start in west, but cloudier in Kent with isolated showers. Then dry with sunny periods. Increasing cloud in west later will bring coastal showers with freshening southerly winds. Chilly inland, but less cold near coasts. Maximum Temperature 8C.</Paragraph>
</Period>
</FcstPeriods>
</RegionalFcst>


My XSLT:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="FcstPeriods/Period/Paragraph"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


I've changed the root to /RegionalFcst and attempted other similar changes, such as adding a leading slash before FcstPeriods, but nothing works until I remove the first and last line from the source XML - then it works perfectly.



This is fine in testing, but of course I want to use the web service provided by Met Office and that's how they present it.



Any ideas?










share|improve this question




















  • 1





    it is another case of having a default namespace. search this site for examples

    – Joel M. Lamsen
    Jan 13 '16 at 6:10






  • 1





    Specifically, searching for "XSLT default namespace" will take you to 506 other people who have asked the same question.

    – Michael Kay
    Jan 13 '16 at 8:25
















0















I'm trying to extract the headline from the below XML from the Met Office web service using XSLT, however my XSLT select returns blank.



SOURCE:



<RegionalFcst xmlns="www.metoffice.gov.uk/xml/metoRegionalFcst" createdOn="2016-01-13T02:14:39" issuedAt="2016-01-13T04:00:00" regionId="se">
<FcstPeriods>
<Period id="day1to2">
<Paragraph title="Headline:">Frosty start. Bright or sunny day.</Paragraph>
<Paragraph title="Today:">A clear and frosty start in west, but cloudier in Kent with isolated showers. Then dry with sunny periods. Increasing cloud in west later will bring coastal showers with freshening southerly winds. Chilly inland, but less cold near coasts. Maximum Temperature 8C.</Paragraph>
</Period>
</FcstPeriods>
</RegionalFcst>


My XSLT:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="FcstPeriods/Period/Paragraph"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


I've changed the root to /RegionalFcst and attempted other similar changes, such as adding a leading slash before FcstPeriods, but nothing works until I remove the first and last line from the source XML - then it works perfectly.



This is fine in testing, but of course I want to use the web service provided by Met Office and that's how they present it.



Any ideas?










share|improve this question




















  • 1





    it is another case of having a default namespace. search this site for examples

    – Joel M. Lamsen
    Jan 13 '16 at 6:10






  • 1





    Specifically, searching for "XSLT default namespace" will take you to 506 other people who have asked the same question.

    – Michael Kay
    Jan 13 '16 at 8:25














0












0








0








I'm trying to extract the headline from the below XML from the Met Office web service using XSLT, however my XSLT select returns blank.



SOURCE:



<RegionalFcst xmlns="www.metoffice.gov.uk/xml/metoRegionalFcst" createdOn="2016-01-13T02:14:39" issuedAt="2016-01-13T04:00:00" regionId="se">
<FcstPeriods>
<Period id="day1to2">
<Paragraph title="Headline:">Frosty start. Bright or sunny day.</Paragraph>
<Paragraph title="Today:">A clear and frosty start in west, but cloudier in Kent with isolated showers. Then dry with sunny periods. Increasing cloud in west later will bring coastal showers with freshening southerly winds. Chilly inland, but less cold near coasts. Maximum Temperature 8C.</Paragraph>
</Period>
</FcstPeriods>
</RegionalFcst>


My XSLT:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="FcstPeriods/Period/Paragraph"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


I've changed the root to /RegionalFcst and attempted other similar changes, such as adding a leading slash before FcstPeriods, but nothing works until I remove the first and last line from the source XML - then it works perfectly.



This is fine in testing, but of course I want to use the web service provided by Met Office and that's how they present it.



Any ideas?










share|improve this question
















I'm trying to extract the headline from the below XML from the Met Office web service using XSLT, however my XSLT select returns blank.



SOURCE:



<RegionalFcst xmlns="www.metoffice.gov.uk/xml/metoRegionalFcst" createdOn="2016-01-13T02:14:39" issuedAt="2016-01-13T04:00:00" regionId="se">
<FcstPeriods>
<Period id="day1to2">
<Paragraph title="Headline:">Frosty start. Bright or sunny day.</Paragraph>
<Paragraph title="Today:">A clear and frosty start in west, but cloudier in Kent with isolated showers. Then dry with sunny periods. Increasing cloud in west later will bring coastal showers with freshening southerly winds. Chilly inland, but less cold near coasts. Maximum Temperature 8C.</Paragraph>
</Period>
</FcstPeriods>
</RegionalFcst>


My XSLT:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="FcstPeriods/Period/Paragraph"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>


I've changed the root to /RegionalFcst and attempted other similar changes, such as adding a leading slash before FcstPeriods, but nothing works until I remove the first and last line from the source XML - then it works perfectly.



This is fine in testing, but of course I want to use the web service provided by Met Office and that's how they present it.



Any ideas?







xml xslt






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 13 '16 at 5:01







hazymat

















asked Jan 13 '16 at 4:36









hazymathazymat

139213




139213








  • 1





    it is another case of having a default namespace. search this site for examples

    – Joel M. Lamsen
    Jan 13 '16 at 6:10






  • 1





    Specifically, searching for "XSLT default namespace" will take you to 506 other people who have asked the same question.

    – Michael Kay
    Jan 13 '16 at 8:25














  • 1





    it is another case of having a default namespace. search this site for examples

    – Joel M. Lamsen
    Jan 13 '16 at 6:10






  • 1





    Specifically, searching for "XSLT default namespace" will take you to 506 other people who have asked the same question.

    – Michael Kay
    Jan 13 '16 at 8:25








1




1





it is another case of having a default namespace. search this site for examples

– Joel M. Lamsen
Jan 13 '16 at 6:10





it is another case of having a default namespace. search this site for examples

– Joel M. Lamsen
Jan 13 '16 at 6:10




1




1





Specifically, searching for "XSLT default namespace" will take you to 506 other people who have asked the same question.

– Michael Kay
Jan 13 '16 at 8:25





Specifically, searching for "XSLT default namespace" will take you to 506 other people who have asked the same question.

– Michael Kay
Jan 13 '16 at 8:25












3 Answers
3






active

oldest

votes


















6














The problem: your XML puts its elements in a namespace.



Solution: declare the same namespace in your stylesheet, assign it a prefix and use that prefix to address the elements in the source XML:



XSLT 1.0



<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:met="www.metoffice.gov.uk/xml/metoRegionalFcst"
exclude-result-prefixes="met">
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="met:RegionalFcst/met:FcstPeriods/met:Period/met:Paragraph[@title='Headline:']"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>





share|improve this answer
























  • Follow-up question. I need to remove html tags from the response as I'm not processing for web. When I remove <html><body>, </body></html>, the response I get is <?xml version="1.0" encoding="UTF-8"?>Frosty start. Bright or sunny day. I need this response without the <?xml....> tag. Why would I be getting this and how do I remove it? Thanks for your help.

    – hazymat
    Jan 13 '16 at 13:30











  • @hazymat Could you edit your question and post the exact result you want to get (as code)?

    – michael.hor257k
    Jan 13 '16 at 13:35











  • Please ignore my last comment, I had forgotten I needed to include another line to properly encode the output for the system I was using. So it's working as intended. Thanks again for your help.

    – hazymat
    Jan 13 '16 at 13:42











  • @michael.hor257k thx , even I was facing the same issue and as per ur suggestion it worked.

    – sreevathsa a
    Oct 28 '16 at 5:28











  • Thanks this helped solving my problem, too. It should be emphasized that this only works for the default namespace "xmlns=...". If there are any other qualified namespaces in the source xml file they have to be added to "xsl:stylesheet", used in the xpath (without the temporary prefix for the default namespace), and added to "exclude-result-prefixes" (as space separated list).

    – Stefan Dolezel
    Jun 1 '17 at 9:10



















0














Below is the simple change needed in your xsl.



from:
<xsl:value-of select="FcstPeriods/Period/Paragraph"/>



to:
<xsl:value-of select="//*:FcstPeriods/*:Period/*:Paragraph"/>






share|improve this answer
























  • I don't think //*:FcstPeriods is valid XPath syntax.

    – Kim Homann
    Jan 13 '16 at 8:33











  • @Kimmy, check here

    – Rao
    Jan 13 '16 at 8:58






  • 1





    This is not a good answer. Namespaces are presumed to be there for a reason. Ignoring them is not good practice.

    – michael.hor257k
    Jan 13 '16 at 9:18













  • @Rao: Maybe this depends on the XPath version, I don't know.

    – Kim Homann
    Jan 13 '16 at 11:58






  • 1





    @Kimmy You are correct, *:node is an XPath 2.0 pattern.

    – michael.hor257k
    Jan 13 '16 at 12:38



















0














There are 2 mistakes in your XSL:





  1. <xsl:value-of select="FcstPeriods/Period/Paragraph"/> will never select anything because <RegionalFcst> and all its child elements are namespaced (xmlns="www.metoffice.gov.uk/xml/metoRegionalFcst").


  2. <xsl:template match="/"> will not match <RegionalFcst> but it will match its parent, the (invisible) document element. <RegionalFcst> is the first and only child of /.


For your XSL to work properly, it would have to look like this:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="*[local-name()='RegionalFcst']/*[local-name()='FcstPeriods']/*[local-name()='Period']/*[local-name()='Paragraph']"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>





share|improve this answer



















  • 1





    This is not a good answer. Namespaces are presumed to be there for a reason. Ignoring them is not good practice.

    – michael.hor257k
    Jan 13 '16 at 9:18











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34758492%2fxslt-transform-doesnt-work-until-i-remove-root-node%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









6














The problem: your XML puts its elements in a namespace.



Solution: declare the same namespace in your stylesheet, assign it a prefix and use that prefix to address the elements in the source XML:



XSLT 1.0



<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:met="www.metoffice.gov.uk/xml/metoRegionalFcst"
exclude-result-prefixes="met">
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="met:RegionalFcst/met:FcstPeriods/met:Period/met:Paragraph[@title='Headline:']"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>





share|improve this answer
























  • Follow-up question. I need to remove html tags from the response as I'm not processing for web. When I remove <html><body>, </body></html>, the response I get is <?xml version="1.0" encoding="UTF-8"?>Frosty start. Bright or sunny day. I need this response without the <?xml....> tag. Why would I be getting this and how do I remove it? Thanks for your help.

    – hazymat
    Jan 13 '16 at 13:30











  • @hazymat Could you edit your question and post the exact result you want to get (as code)?

    – michael.hor257k
    Jan 13 '16 at 13:35











  • Please ignore my last comment, I had forgotten I needed to include another line to properly encode the output for the system I was using. So it's working as intended. Thanks again for your help.

    – hazymat
    Jan 13 '16 at 13:42











  • @michael.hor257k thx , even I was facing the same issue and as per ur suggestion it worked.

    – sreevathsa a
    Oct 28 '16 at 5:28











  • Thanks this helped solving my problem, too. It should be emphasized that this only works for the default namespace "xmlns=...". If there are any other qualified namespaces in the source xml file they have to be added to "xsl:stylesheet", used in the xpath (without the temporary prefix for the default namespace), and added to "exclude-result-prefixes" (as space separated list).

    – Stefan Dolezel
    Jun 1 '17 at 9:10
















6














The problem: your XML puts its elements in a namespace.



Solution: declare the same namespace in your stylesheet, assign it a prefix and use that prefix to address the elements in the source XML:



XSLT 1.0



<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:met="www.metoffice.gov.uk/xml/metoRegionalFcst"
exclude-result-prefixes="met">
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="met:RegionalFcst/met:FcstPeriods/met:Period/met:Paragraph[@title='Headline:']"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>





share|improve this answer
























  • Follow-up question. I need to remove html tags from the response as I'm not processing for web. When I remove <html><body>, </body></html>, the response I get is <?xml version="1.0" encoding="UTF-8"?>Frosty start. Bright or sunny day. I need this response without the <?xml....> tag. Why would I be getting this and how do I remove it? Thanks for your help.

    – hazymat
    Jan 13 '16 at 13:30











  • @hazymat Could you edit your question and post the exact result you want to get (as code)?

    – michael.hor257k
    Jan 13 '16 at 13:35











  • Please ignore my last comment, I had forgotten I needed to include another line to properly encode the output for the system I was using. So it's working as intended. Thanks again for your help.

    – hazymat
    Jan 13 '16 at 13:42











  • @michael.hor257k thx , even I was facing the same issue and as per ur suggestion it worked.

    – sreevathsa a
    Oct 28 '16 at 5:28











  • Thanks this helped solving my problem, too. It should be emphasized that this only works for the default namespace "xmlns=...". If there are any other qualified namespaces in the source xml file they have to be added to "xsl:stylesheet", used in the xpath (without the temporary prefix for the default namespace), and added to "exclude-result-prefixes" (as space separated list).

    – Stefan Dolezel
    Jun 1 '17 at 9:10














6












6








6







The problem: your XML puts its elements in a namespace.



Solution: declare the same namespace in your stylesheet, assign it a prefix and use that prefix to address the elements in the source XML:



XSLT 1.0



<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:met="www.metoffice.gov.uk/xml/metoRegionalFcst"
exclude-result-prefixes="met">
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="met:RegionalFcst/met:FcstPeriods/met:Period/met:Paragraph[@title='Headline:']"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>





share|improve this answer













The problem: your XML puts its elements in a namespace.



Solution: declare the same namespace in your stylesheet, assign it a prefix and use that prefix to address the elements in the source XML:



XSLT 1.0



<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:met="www.metoffice.gov.uk/xml/metoRegionalFcst"
exclude-result-prefixes="met">
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="met:RegionalFcst/met:FcstPeriods/met:Period/met:Paragraph[@title='Headline:']"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 13 '16 at 9:17









michael.hor257kmichael.hor257k

74.6k42236




74.6k42236













  • Follow-up question. I need to remove html tags from the response as I'm not processing for web. When I remove <html><body>, </body></html>, the response I get is <?xml version="1.0" encoding="UTF-8"?>Frosty start. Bright or sunny day. I need this response without the <?xml....> tag. Why would I be getting this and how do I remove it? Thanks for your help.

    – hazymat
    Jan 13 '16 at 13:30











  • @hazymat Could you edit your question and post the exact result you want to get (as code)?

    – michael.hor257k
    Jan 13 '16 at 13:35











  • Please ignore my last comment, I had forgotten I needed to include another line to properly encode the output for the system I was using. So it's working as intended. Thanks again for your help.

    – hazymat
    Jan 13 '16 at 13:42











  • @michael.hor257k thx , even I was facing the same issue and as per ur suggestion it worked.

    – sreevathsa a
    Oct 28 '16 at 5:28











  • Thanks this helped solving my problem, too. It should be emphasized that this only works for the default namespace "xmlns=...". If there are any other qualified namespaces in the source xml file they have to be added to "xsl:stylesheet", used in the xpath (without the temporary prefix for the default namespace), and added to "exclude-result-prefixes" (as space separated list).

    – Stefan Dolezel
    Jun 1 '17 at 9:10



















  • Follow-up question. I need to remove html tags from the response as I'm not processing for web. When I remove <html><body>, </body></html>, the response I get is <?xml version="1.0" encoding="UTF-8"?>Frosty start. Bright or sunny day. I need this response without the <?xml....> tag. Why would I be getting this and how do I remove it? Thanks for your help.

    – hazymat
    Jan 13 '16 at 13:30











  • @hazymat Could you edit your question and post the exact result you want to get (as code)?

    – michael.hor257k
    Jan 13 '16 at 13:35











  • Please ignore my last comment, I had forgotten I needed to include another line to properly encode the output for the system I was using. So it's working as intended. Thanks again for your help.

    – hazymat
    Jan 13 '16 at 13:42











  • @michael.hor257k thx , even I was facing the same issue and as per ur suggestion it worked.

    – sreevathsa a
    Oct 28 '16 at 5:28











  • Thanks this helped solving my problem, too. It should be emphasized that this only works for the default namespace "xmlns=...". If there are any other qualified namespaces in the source xml file they have to be added to "xsl:stylesheet", used in the xpath (without the temporary prefix for the default namespace), and added to "exclude-result-prefixes" (as space separated list).

    – Stefan Dolezel
    Jun 1 '17 at 9:10

















Follow-up question. I need to remove html tags from the response as I'm not processing for web. When I remove <html><body>, </body></html>, the response I get is <?xml version="1.0" encoding="UTF-8"?>Frosty start. Bright or sunny day. I need this response without the <?xml....> tag. Why would I be getting this and how do I remove it? Thanks for your help.

– hazymat
Jan 13 '16 at 13:30





Follow-up question. I need to remove html tags from the response as I'm not processing for web. When I remove <html><body>, </body></html>, the response I get is <?xml version="1.0" encoding="UTF-8"?>Frosty start. Bright or sunny day. I need this response without the <?xml....> tag. Why would I be getting this and how do I remove it? Thanks for your help.

– hazymat
Jan 13 '16 at 13:30













@hazymat Could you edit your question and post the exact result you want to get (as code)?

– michael.hor257k
Jan 13 '16 at 13:35





@hazymat Could you edit your question and post the exact result you want to get (as code)?

– michael.hor257k
Jan 13 '16 at 13:35













Please ignore my last comment, I had forgotten I needed to include another line to properly encode the output for the system I was using. So it's working as intended. Thanks again for your help.

– hazymat
Jan 13 '16 at 13:42





Please ignore my last comment, I had forgotten I needed to include another line to properly encode the output for the system I was using. So it's working as intended. Thanks again for your help.

– hazymat
Jan 13 '16 at 13:42













@michael.hor257k thx , even I was facing the same issue and as per ur suggestion it worked.

– sreevathsa a
Oct 28 '16 at 5:28





@michael.hor257k thx , even I was facing the same issue and as per ur suggestion it worked.

– sreevathsa a
Oct 28 '16 at 5:28













Thanks this helped solving my problem, too. It should be emphasized that this only works for the default namespace "xmlns=...". If there are any other qualified namespaces in the source xml file they have to be added to "xsl:stylesheet", used in the xpath (without the temporary prefix for the default namespace), and added to "exclude-result-prefixes" (as space separated list).

– Stefan Dolezel
Jun 1 '17 at 9:10





Thanks this helped solving my problem, too. It should be emphasized that this only works for the default namespace "xmlns=...". If there are any other qualified namespaces in the source xml file they have to be added to "xsl:stylesheet", used in the xpath (without the temporary prefix for the default namespace), and added to "exclude-result-prefixes" (as space separated list).

– Stefan Dolezel
Jun 1 '17 at 9:10













0














Below is the simple change needed in your xsl.



from:
<xsl:value-of select="FcstPeriods/Period/Paragraph"/>



to:
<xsl:value-of select="//*:FcstPeriods/*:Period/*:Paragraph"/>






share|improve this answer
























  • I don't think //*:FcstPeriods is valid XPath syntax.

    – Kim Homann
    Jan 13 '16 at 8:33











  • @Kimmy, check here

    – Rao
    Jan 13 '16 at 8:58






  • 1





    This is not a good answer. Namespaces are presumed to be there for a reason. Ignoring them is not good practice.

    – michael.hor257k
    Jan 13 '16 at 9:18













  • @Rao: Maybe this depends on the XPath version, I don't know.

    – Kim Homann
    Jan 13 '16 at 11:58






  • 1





    @Kimmy You are correct, *:node is an XPath 2.0 pattern.

    – michael.hor257k
    Jan 13 '16 at 12:38
















0














Below is the simple change needed in your xsl.



from:
<xsl:value-of select="FcstPeriods/Period/Paragraph"/>



to:
<xsl:value-of select="//*:FcstPeriods/*:Period/*:Paragraph"/>






share|improve this answer
























  • I don't think //*:FcstPeriods is valid XPath syntax.

    – Kim Homann
    Jan 13 '16 at 8:33











  • @Kimmy, check here

    – Rao
    Jan 13 '16 at 8:58






  • 1





    This is not a good answer. Namespaces are presumed to be there for a reason. Ignoring them is not good practice.

    – michael.hor257k
    Jan 13 '16 at 9:18













  • @Rao: Maybe this depends on the XPath version, I don't know.

    – Kim Homann
    Jan 13 '16 at 11:58






  • 1





    @Kimmy You are correct, *:node is an XPath 2.0 pattern.

    – michael.hor257k
    Jan 13 '16 at 12:38














0












0








0







Below is the simple change needed in your xsl.



from:
<xsl:value-of select="FcstPeriods/Period/Paragraph"/>



to:
<xsl:value-of select="//*:FcstPeriods/*:Period/*:Paragraph"/>






share|improve this answer













Below is the simple change needed in your xsl.



from:
<xsl:value-of select="FcstPeriods/Period/Paragraph"/>



to:
<xsl:value-of select="//*:FcstPeriods/*:Period/*:Paragraph"/>







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 13 '16 at 6:44









RaoRao

15.4k93449




15.4k93449













  • I don't think //*:FcstPeriods is valid XPath syntax.

    – Kim Homann
    Jan 13 '16 at 8:33











  • @Kimmy, check here

    – Rao
    Jan 13 '16 at 8:58






  • 1





    This is not a good answer. Namespaces are presumed to be there for a reason. Ignoring them is not good practice.

    – michael.hor257k
    Jan 13 '16 at 9:18













  • @Rao: Maybe this depends on the XPath version, I don't know.

    – Kim Homann
    Jan 13 '16 at 11:58






  • 1





    @Kimmy You are correct, *:node is an XPath 2.0 pattern.

    – michael.hor257k
    Jan 13 '16 at 12:38



















  • I don't think //*:FcstPeriods is valid XPath syntax.

    – Kim Homann
    Jan 13 '16 at 8:33











  • @Kimmy, check here

    – Rao
    Jan 13 '16 at 8:58






  • 1





    This is not a good answer. Namespaces are presumed to be there for a reason. Ignoring them is not good practice.

    – michael.hor257k
    Jan 13 '16 at 9:18













  • @Rao: Maybe this depends on the XPath version, I don't know.

    – Kim Homann
    Jan 13 '16 at 11:58






  • 1





    @Kimmy You are correct, *:node is an XPath 2.0 pattern.

    – michael.hor257k
    Jan 13 '16 at 12:38

















I don't think //*:FcstPeriods is valid XPath syntax.

– Kim Homann
Jan 13 '16 at 8:33





I don't think //*:FcstPeriods is valid XPath syntax.

– Kim Homann
Jan 13 '16 at 8:33













@Kimmy, check here

– Rao
Jan 13 '16 at 8:58





@Kimmy, check here

– Rao
Jan 13 '16 at 8:58




1




1





This is not a good answer. Namespaces are presumed to be there for a reason. Ignoring them is not good practice.

– michael.hor257k
Jan 13 '16 at 9:18







This is not a good answer. Namespaces are presumed to be there for a reason. Ignoring them is not good practice.

– michael.hor257k
Jan 13 '16 at 9:18















@Rao: Maybe this depends on the XPath version, I don't know.

– Kim Homann
Jan 13 '16 at 11:58





@Rao: Maybe this depends on the XPath version, I don't know.

– Kim Homann
Jan 13 '16 at 11:58




1




1





@Kimmy You are correct, *:node is an XPath 2.0 pattern.

– michael.hor257k
Jan 13 '16 at 12:38





@Kimmy You are correct, *:node is an XPath 2.0 pattern.

– michael.hor257k
Jan 13 '16 at 12:38











0














There are 2 mistakes in your XSL:





  1. <xsl:value-of select="FcstPeriods/Period/Paragraph"/> will never select anything because <RegionalFcst> and all its child elements are namespaced (xmlns="www.metoffice.gov.uk/xml/metoRegionalFcst").


  2. <xsl:template match="/"> will not match <RegionalFcst> but it will match its parent, the (invisible) document element. <RegionalFcst> is the first and only child of /.


For your XSL to work properly, it would have to look like this:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="*[local-name()='RegionalFcst']/*[local-name()='FcstPeriods']/*[local-name()='Period']/*[local-name()='Paragraph']"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>





share|improve this answer



















  • 1





    This is not a good answer. Namespaces are presumed to be there for a reason. Ignoring them is not good practice.

    – michael.hor257k
    Jan 13 '16 at 9:18
















0














There are 2 mistakes in your XSL:





  1. <xsl:value-of select="FcstPeriods/Period/Paragraph"/> will never select anything because <RegionalFcst> and all its child elements are namespaced (xmlns="www.metoffice.gov.uk/xml/metoRegionalFcst").


  2. <xsl:template match="/"> will not match <RegionalFcst> but it will match its parent, the (invisible) document element. <RegionalFcst> is the first and only child of /.


For your XSL to work properly, it would have to look like this:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="*[local-name()='RegionalFcst']/*[local-name()='FcstPeriods']/*[local-name()='Period']/*[local-name()='Paragraph']"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>





share|improve this answer



















  • 1





    This is not a good answer. Namespaces are presumed to be there for a reason. Ignoring them is not good practice.

    – michael.hor257k
    Jan 13 '16 at 9:18














0












0








0







There are 2 mistakes in your XSL:





  1. <xsl:value-of select="FcstPeriods/Period/Paragraph"/> will never select anything because <RegionalFcst> and all its child elements are namespaced (xmlns="www.metoffice.gov.uk/xml/metoRegionalFcst").


  2. <xsl:template match="/"> will not match <RegionalFcst> but it will match its parent, the (invisible) document element. <RegionalFcst> is the first and only child of /.


For your XSL to work properly, it would have to look like this:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="*[local-name()='RegionalFcst']/*[local-name()='FcstPeriods']/*[local-name()='Period']/*[local-name()='Paragraph']"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>





share|improve this answer













There are 2 mistakes in your XSL:





  1. <xsl:value-of select="FcstPeriods/Period/Paragraph"/> will never select anything because <RegionalFcst> and all its child elements are namespaced (xmlns="www.metoffice.gov.uk/xml/metoRegionalFcst").


  2. <xsl:template match="/"> will not match <RegionalFcst> but it will match its parent, the (invisible) document element. <RegionalFcst> is the first and only child of /.


For your XSL to work properly, it would have to look like this:



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="*[local-name()='RegionalFcst']/*[local-name()='FcstPeriods']/*[local-name()='Period']/*[local-name()='Paragraph']"/>
</body>
</html>
</xsl:template>
</xsl:stylesheet>






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 13 '16 at 8:32









Kim HomannKim Homann

1,576715




1,576715








  • 1





    This is not a good answer. Namespaces are presumed to be there for a reason. Ignoring them is not good practice.

    – michael.hor257k
    Jan 13 '16 at 9:18














  • 1





    This is not a good answer. Namespaces are presumed to be there for a reason. Ignoring them is not good practice.

    – michael.hor257k
    Jan 13 '16 at 9:18








1




1





This is not a good answer. Namespaces are presumed to be there for a reason. Ignoring them is not good practice.

– michael.hor257k
Jan 13 '16 at 9:18





This is not a good answer. Namespaces are presumed to be there for a reason. Ignoring them is not good practice.

– michael.hor257k
Jan 13 '16 at 9:18


















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f34758492%2fxslt-transform-doesnt-work-until-i-remove-root-node%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory