node-xml icon indicating copy to clipboard operation
node-xml copied to clipboard

How to include a xsl stylesheet?

Open marcofranssen opened this issue 4 years ago • 3 comments

I am trying to include my xsl stylesheet but somehow it doesn't work.

My code:

xml(
    {
      "?xml-stylesheet": [{ _attr: { type: "text/xsl", href: "sitemap.xsl" } }],
      sitemapindex: [
        { _attr: { xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9" } },
        { sitemap: [
          { loc: "https://nextjs.marcofranssen.nl/blog-sitemap.xml" }, 
          { lastmod: new Date().toISOString() },
        ]
      ],
    },
    { declaration: true }
)

Result:

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="sitemap.xsl"></?xml-stylesheet>

Expected:

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="sitemap.xsl"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
    <loc>https://nextjs.marcofranssen.nl/blog-sitemap.xml</loc>
    <lastmod>2021-01-24T12:55:02.245Z</lastmod>
  </sitemap>
</sitemapindex>

marcofranssen avatar Jan 24 '21 13:01 marcofranssen

var xml = require("xml")
console.log(xml(
    [
      {"?xml-stylesheet": [{ _attr: { type: "text/xsl", href: "sitemap.xsl" } }]},
      {"sitemapindex": [
        { _attr: { xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9" } },
        { sitemap: [
            { loc: "https://nextjs.marcofranssen.nl/blog-sitemap.xml" }, 
            { lastmod: new Date().toISOString() },
          ]
        },
      ]},
      
  ], { declaration: [{version:"1.0",encoding:"UTF-8"}] }
))

LiuQixuan avatar Jun 05 '21 14:06 LiuQixuan

@LiuQixuan

var xml = require("xml")
console.log(xml(
    [
      {"?xml-stylesheet": [{ _attr: { type: "text/xsl", href: "sitemap.xsl" } }]},
      {"sitemapindex": [
        { _attr: { xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9" } },
        { sitemap: [
            { loc: "https://nextjs.marcofranssen.nl/blog-sitemap.xml" }, 
            { lastmod: new Date().toISOString() },
          ]
        },
      ]},
      
  ], { declaration: [{version:"1.0",encoding:"UTF-8"}] }
))

2021-07-22 16-25-09 的屏幕截图

Seems that It doesn't work.

CBW2007 avatar Jul 22 '21 08:07 CBW2007

Indeed the code you shown is the code I'm using @LiuQixuan. See the result vs the thing I would expect.

marcofranssen avatar Jul 29 '21 11:07 marcofranssen