LrXml:transform() in Adobe Lightroom SDK does not match root node properly

  • 2
  • Problem
  • Updated 6 years ago
LrXml:transform() does not match the root node (the parent of the root element) in XSL templates. This only happens in Windows. To reproduce this bug create an Info.lua like so:

return {
LrSdkVersion = "4.0",
LrToolkitIdentifier = "xslttest.bug",
LrPluginName = "Test XSLT",
LrExportMenuItems = {
{
title = 'Test XSLT',
file = 'TestXSLT.lua'
}
},
}

and a file name TestXSLT.lua like so:

local logger = import('LrLogger')()
logger:enable('logfile')
local LrXml = import('LrXml')

local xml_data = [[

]]

local xslt_data = [[

ROOT
FIRST
SECOND

]]

logger:debug('Parsing xml: ' .. xml_data)
local xml = LrXml.parseXml(xml_data)
logger:debug('Applying xslt: ' .. xslt_data)
local res = xml:transform(xslt_data)
logger:debug('Result: ' .. res)

The correct output should be ROOTFIRSTSECOND. Adobe Lightroom 4.1 on Windows 7 produces FIRSTSECOND which is incorrect.
Photo of Alkis Evlogimenos

Alkis Evlogimenos

  • 2 Posts
  • 0 Reply Likes

Posted 6 years ago

  • 2
Photo of Matt Dawson

Matt Dawson

  • 8 Posts
  • 2 Reply Likes
FYI The code pasted here is missing the XML and XSLT string definitions.

But I've run a variant of this code (as posted in the SDK forums) and did notice the behaviour discussed.

Matt
Photo of Alkis Evlogimenos

Alkis Evlogimenos

  • 2 Posts
  • 0 Reply Likes
Another try for the code sample.

Info.lua:



return {
LrSdkVersion = "4.0",
LrToolkitIdentifier = "xslttest.bug",
LrPluginName = "Test XSLT",
LrExportMenuItems = {
{
title = 'Test XSLT',
file = 'TestXSLT.lua'
}
},
}


TestXSLT.lua:



local logger = import('LrLogger')()
logger:enable('logfile')
local LrXml = import('LrXml')

local xml_data = [[
<?xml version='1.0' encoding='UTF-8'?>
<first>
<second />
</first>
]]

local xslt_data = [[
<xsl:stylesheet version='1.0' xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method='text'/>

<xsl:template match='/'>ROOT<xsl:apply-templates/></xsl:template>
<xsl:template match='first'>FIRST<xsl:apply-templates/></xsl:template>
<xsl:template match='second'>SECOND<xsl:apply-templates/></xsl:template>
</xsl:stylesheet>
]]

logger:debug('Parsing xml: ' .. xml_data)
local xml = LrXml.parseXml(xml_data)
logger:debug('Applying xslt: ' .. xslt_data)
local res = xml:transform(xslt_data)
logger:debug('Result: ' .. res)