XSLT unable to remove line break before and after attribute value
up vote
0
down vote
favorite
I am trying to transform an XML schema with XSLT 3.0 with Saxon 9.9 HE into a JSON. The transformation is working. However, when I output the value of an attribute it is coming with a line break before and after the name. The XSD fragment is below:
<group name="imapAttachmentDownloaderGroup">
<annotation>
<documentation>
Configuration block definitions for IMAP attachment downloader delegate. It contains all the configuration
block definitions that are required to configure the delegate successfully.
</documentation>
</annotation>
<sequence>
<element name="IMAPConnectorConfig">
<complexType>
<attribute name="imapHost" use="required" type="string">
<annotation>
<documentation>
This configuration block deals with the IMAP server name or IP address to where the
connection is to be made to download the attachments.
Example: "outlook.office365.com" or "40.100.137.66"
</documentation>
</annotation>
</attribute>
<attribute name="imapPort" use="required" type="int">
<annotation>
<documentation>
The port to use to connect to the server, defaults to 993.
Example: "993"
</documentation>
</annotation>
</attribute>
....
The SXL is as below:
<?xml version="1.0" encoding="UTF-8"?>
<stylesheet version="3.0"
xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.proviseconsulting.com/ProcessConfig"
xmlns:saxon="http://saxon.sf.net/"
xsi:schemaLocation="http://www.w3.org/1999/XSL/Transform
https://www.w3.org/2007/schema-for-xslt20.xsd">
<mode on-no-match="shallow-skip"/>
<output method="text" encoding="utf-8" indent="no" media-type="application/json" normalization-form="true"/>
<strip-space elements="*" />
<!-- <template match="text()|@*"/> -->
<param name="delegateGroupName" required="yes"/>
<template match="/child::xsi:schema/child::xsi:group[attribute::name=$delegateGroupName]">
<variable name="xx" select="attribute::name"/>
{'groupName':'<value-of select="normalize-space($xx)"/>'
<for-each select="child::xsi:sequence/child::xsi:element">
,'<value-of select="attribute::name"/>':{
<for-each select="child::xsi:complexType/child::xsi:attribute">
<choose>
<when test="position()=last()">'name':'<value-of select="attribute::name"/>'</when>
<otherwise>'name':'<value-of select="attribute::name"/>',</otherwise>
</choose>
</for-each>
<for-each select="child::xsi:complexType/child::xsi:attributeGroup">
<value-of select="attribute::ref"/>
</for-each>
}
</for-each>
}
<!-- <apply-templates select="attribute::name"/> -->
</template>
The output is:
{'groupName':'
imapAttachmentDownloaderGroup
'
, '
IMAPConnectorConfig
':{
'name':'
imapHost
',
'name':'
imapPort
',
'name':'
sslEnabled
',
'name':'
startTLSEnabled
',
'name':'
imapUser
',
'name':'
imapPassword
',
'name':'
credentialId
I have tried all the mechanisms that I could find in the posts assigning it to variable, normalize-space, normalize-space with string() with data(). Nothing seems to be working. Any help would be sincerely appreciated.
=== Including complete example ===
XSL (removed all the comments and other elements):
<?xml version="1.0" encoding="UTF-8"?>
<stylesheet version="3.0"
xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.proviseconsulting.com/ProcessConfig"
xmlns:saxon="http://saxon.sf.net/"
xsi:schemaLocation="http://www.w3.org/1999/XSL/Transform
https://www.w3.org/2007/schema-for-xslt20.xsd">
<mode on-no-match="shallow-skip"/>
<output method="text" encoding="utf-8" indent="no" media-type="application/json" normalization-form="true"/>
<strip-space elements="*" />
<param name="delegateGroupName" required="yes"/>
<template match="/child::xsi:schema/child::xsi:group[attribute::name=$delegateGroupName]">
<text>{"groupName":"</text><value-of select="attribute::name/normalize-space()"/><text>"}</text>
</template>
=== Output ===
{"groupName":"
imapAttachmentDownloaderGroup
"}
The input XSD remains the same. The Java code is as below:
String xsdFilePath="file:///D:/workspaces/mtplatform/PlatformManual_V1/PlatformManual/ProcessConfiguration/ProcessConfiguration.xsd";
String xslFilePath="file:///D:/workspaces/mtplatform/PlatformManual_V1/PlatformManual/ProcessConfiguration/ProcessConfiguration.xsl";
Processor processor=new Processor(false);
XdmNode node=processor.newDocumentBuilder().build(new File(new URI(xsdFilePath)));
XsltCompiler xsltCompiler=processor.newXsltCompiler();
//xsltCompiler.setParameter(new QName("delegateGroupName"), XdmValue.makeValue("imapAttachmentDownloaderGroup"));
StreamSource xsdSource=new StreamSource(new FileInputStream(new File(new URI(xsdFilePath))));
StreamSource xslSource=new StreamSource(new FileInputStream(new File(new URI(xslFilePath))));
XsltExecutable compiledXSL=xsltCompiler.compile(xslSource);
Xslt30Transformer xslTransformer=compiledXSL.load30();
HashMap<QName, XdmValue> parameterMap=new HashMap<>();
parameterMap.put(new QName("delegateGroupName"), XdmValue.makeValue("imapAttachmentDownloaderGroup"));
xslTransformer.setStylesheetParameters(parameterMap);
XdmValue output=xslTransformer.applyTemplates(node);
System.out.println(output.toString());
xml xslt xsd saxon
|
show 3 more comments
up vote
0
down vote
favorite
I am trying to transform an XML schema with XSLT 3.0 with Saxon 9.9 HE into a JSON. The transformation is working. However, when I output the value of an attribute it is coming with a line break before and after the name. The XSD fragment is below:
<group name="imapAttachmentDownloaderGroup">
<annotation>
<documentation>
Configuration block definitions for IMAP attachment downloader delegate. It contains all the configuration
block definitions that are required to configure the delegate successfully.
</documentation>
</annotation>
<sequence>
<element name="IMAPConnectorConfig">
<complexType>
<attribute name="imapHost" use="required" type="string">
<annotation>
<documentation>
This configuration block deals with the IMAP server name or IP address to where the
connection is to be made to download the attachments.
Example: "outlook.office365.com" or "40.100.137.66"
</documentation>
</annotation>
</attribute>
<attribute name="imapPort" use="required" type="int">
<annotation>
<documentation>
The port to use to connect to the server, defaults to 993.
Example: "993"
</documentation>
</annotation>
</attribute>
....
The SXL is as below:
<?xml version="1.0" encoding="UTF-8"?>
<stylesheet version="3.0"
xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.proviseconsulting.com/ProcessConfig"
xmlns:saxon="http://saxon.sf.net/"
xsi:schemaLocation="http://www.w3.org/1999/XSL/Transform
https://www.w3.org/2007/schema-for-xslt20.xsd">
<mode on-no-match="shallow-skip"/>
<output method="text" encoding="utf-8" indent="no" media-type="application/json" normalization-form="true"/>
<strip-space elements="*" />
<!-- <template match="text()|@*"/> -->
<param name="delegateGroupName" required="yes"/>
<template match="/child::xsi:schema/child::xsi:group[attribute::name=$delegateGroupName]">
<variable name="xx" select="attribute::name"/>
{'groupName':'<value-of select="normalize-space($xx)"/>'
<for-each select="child::xsi:sequence/child::xsi:element">
,'<value-of select="attribute::name"/>':{
<for-each select="child::xsi:complexType/child::xsi:attribute">
<choose>
<when test="position()=last()">'name':'<value-of select="attribute::name"/>'</when>
<otherwise>'name':'<value-of select="attribute::name"/>',</otherwise>
</choose>
</for-each>
<for-each select="child::xsi:complexType/child::xsi:attributeGroup">
<value-of select="attribute::ref"/>
</for-each>
}
</for-each>
}
<!-- <apply-templates select="attribute::name"/> -->
</template>
The output is:
{'groupName':'
imapAttachmentDownloaderGroup
'
, '
IMAPConnectorConfig
':{
'name':'
imapHost
',
'name':'
imapPort
',
'name':'
sslEnabled
',
'name':'
startTLSEnabled
',
'name':'
imapUser
',
'name':'
imapPassword
',
'name':'
credentialId
I have tried all the mechanisms that I could find in the posts assigning it to variable, normalize-space, normalize-space with string() with data(). Nothing seems to be working. Any help would be sincerely appreciated.
=== Including complete example ===
XSL (removed all the comments and other elements):
<?xml version="1.0" encoding="UTF-8"?>
<stylesheet version="3.0"
xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.proviseconsulting.com/ProcessConfig"
xmlns:saxon="http://saxon.sf.net/"
xsi:schemaLocation="http://www.w3.org/1999/XSL/Transform
https://www.w3.org/2007/schema-for-xslt20.xsd">
<mode on-no-match="shallow-skip"/>
<output method="text" encoding="utf-8" indent="no" media-type="application/json" normalization-form="true"/>
<strip-space elements="*" />
<param name="delegateGroupName" required="yes"/>
<template match="/child::xsi:schema/child::xsi:group[attribute::name=$delegateGroupName]">
<text>{"groupName":"</text><value-of select="attribute::name/normalize-space()"/><text>"}</text>
</template>
=== Output ===
{"groupName":"
imapAttachmentDownloaderGroup
"}
The input XSD remains the same. The Java code is as below:
String xsdFilePath="file:///D:/workspaces/mtplatform/PlatformManual_V1/PlatformManual/ProcessConfiguration/ProcessConfiguration.xsd";
String xslFilePath="file:///D:/workspaces/mtplatform/PlatformManual_V1/PlatformManual/ProcessConfiguration/ProcessConfiguration.xsl";
Processor processor=new Processor(false);
XdmNode node=processor.newDocumentBuilder().build(new File(new URI(xsdFilePath)));
XsltCompiler xsltCompiler=processor.newXsltCompiler();
//xsltCompiler.setParameter(new QName("delegateGroupName"), XdmValue.makeValue("imapAttachmentDownloaderGroup"));
StreamSource xsdSource=new StreamSource(new FileInputStream(new File(new URI(xsdFilePath))));
StreamSource xslSource=new StreamSource(new FileInputStream(new File(new URI(xslFilePath))));
XsltExecutable compiledXSL=xsltCompiler.compile(xslSource);
Xslt30Transformer xslTransformer=compiledXSL.load30();
HashMap<QName, XdmValue> parameterMap=new HashMap<>();
parameterMap.put(new QName("delegateGroupName"), XdmValue.makeValue("imapAttachmentDownloaderGroup"));
xslTransformer.setStylesheetParameters(parameterMap);
XdmValue output=xslTransformer.applyTemplates(node);
System.out.println(output.toString());
xml xslt xsd saxon
You can use<xsl:text>':{</xsl:text>
to make sure you only explicitly output that text and not the line break your current code also includes. However, given that you use XSLT 3 and want JSON output it seems more adequate to use theoutput method="json"
and have the code create the necessary XPath 3.1 map structure.
– Martin Honnen
Nov 19 at 13:48
@MartinHonnen, as suggested tried <text>{'groupName':'</text><value-of select="attribute::name"/><text>'</text> it is still giving the same output wil line breaks ... any help would be appreciated, thanks
– Ironluca
Nov 19 at 14:12
Consider to post minimal but complete samples to allow us to reproduce the problem. When I try to apply my suggestion at xsltfiddle.liberty-development.net/gWmuiKm/1 I get the attribute names on one line'IMAPConnectorConfig':{'name':'imapHost','name':'imapPort'
. Not sure however what kind of JSON that would be with two properties of the same namename
.
– Martin Honnen
Nov 19 at 14:26
As for my suggestion to use output methodjson
and construct XPath 3.1 maps, see xsltfiddle.liberty-development.net/gWmuiKm. I had to adjust the structure to make sense as JSON as having several"name" : "..."
doesn't seem to make sense if JSON is really the target format.
– Martin Honnen
Nov 19 at 14:26
1
Does that attributenormalization-form="true"
onxsl:output
really work for you? It would really help if you post minimal but complete samples to allow others to run the sample to easily reproduce the problem, don't see why we need to have to complete schemas or stylesheet code. Also try running from the command line first. If you want thexsl:output
to have any effect I don't understand why you use the overload ofapplyTemplates
returning a raw result, seems better to use a Destination where serialization happens.
– Martin Honnen
Nov 19 at 16:12
|
show 3 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to transform an XML schema with XSLT 3.0 with Saxon 9.9 HE into a JSON. The transformation is working. However, when I output the value of an attribute it is coming with a line break before and after the name. The XSD fragment is below:
<group name="imapAttachmentDownloaderGroup">
<annotation>
<documentation>
Configuration block definitions for IMAP attachment downloader delegate. It contains all the configuration
block definitions that are required to configure the delegate successfully.
</documentation>
</annotation>
<sequence>
<element name="IMAPConnectorConfig">
<complexType>
<attribute name="imapHost" use="required" type="string">
<annotation>
<documentation>
This configuration block deals with the IMAP server name or IP address to where the
connection is to be made to download the attachments.
Example: "outlook.office365.com" or "40.100.137.66"
</documentation>
</annotation>
</attribute>
<attribute name="imapPort" use="required" type="int">
<annotation>
<documentation>
The port to use to connect to the server, defaults to 993.
Example: "993"
</documentation>
</annotation>
</attribute>
....
The SXL is as below:
<?xml version="1.0" encoding="UTF-8"?>
<stylesheet version="3.0"
xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.proviseconsulting.com/ProcessConfig"
xmlns:saxon="http://saxon.sf.net/"
xsi:schemaLocation="http://www.w3.org/1999/XSL/Transform
https://www.w3.org/2007/schema-for-xslt20.xsd">
<mode on-no-match="shallow-skip"/>
<output method="text" encoding="utf-8" indent="no" media-type="application/json" normalization-form="true"/>
<strip-space elements="*" />
<!-- <template match="text()|@*"/> -->
<param name="delegateGroupName" required="yes"/>
<template match="/child::xsi:schema/child::xsi:group[attribute::name=$delegateGroupName]">
<variable name="xx" select="attribute::name"/>
{'groupName':'<value-of select="normalize-space($xx)"/>'
<for-each select="child::xsi:sequence/child::xsi:element">
,'<value-of select="attribute::name"/>':{
<for-each select="child::xsi:complexType/child::xsi:attribute">
<choose>
<when test="position()=last()">'name':'<value-of select="attribute::name"/>'</when>
<otherwise>'name':'<value-of select="attribute::name"/>',</otherwise>
</choose>
</for-each>
<for-each select="child::xsi:complexType/child::xsi:attributeGroup">
<value-of select="attribute::ref"/>
</for-each>
}
</for-each>
}
<!-- <apply-templates select="attribute::name"/> -->
</template>
The output is:
{'groupName':'
imapAttachmentDownloaderGroup
'
, '
IMAPConnectorConfig
':{
'name':'
imapHost
',
'name':'
imapPort
',
'name':'
sslEnabled
',
'name':'
startTLSEnabled
',
'name':'
imapUser
',
'name':'
imapPassword
',
'name':'
credentialId
I have tried all the mechanisms that I could find in the posts assigning it to variable, normalize-space, normalize-space with string() with data(). Nothing seems to be working. Any help would be sincerely appreciated.
=== Including complete example ===
XSL (removed all the comments and other elements):
<?xml version="1.0" encoding="UTF-8"?>
<stylesheet version="3.0"
xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.proviseconsulting.com/ProcessConfig"
xmlns:saxon="http://saxon.sf.net/"
xsi:schemaLocation="http://www.w3.org/1999/XSL/Transform
https://www.w3.org/2007/schema-for-xslt20.xsd">
<mode on-no-match="shallow-skip"/>
<output method="text" encoding="utf-8" indent="no" media-type="application/json" normalization-form="true"/>
<strip-space elements="*" />
<param name="delegateGroupName" required="yes"/>
<template match="/child::xsi:schema/child::xsi:group[attribute::name=$delegateGroupName]">
<text>{"groupName":"</text><value-of select="attribute::name/normalize-space()"/><text>"}</text>
</template>
=== Output ===
{"groupName":"
imapAttachmentDownloaderGroup
"}
The input XSD remains the same. The Java code is as below:
String xsdFilePath="file:///D:/workspaces/mtplatform/PlatformManual_V1/PlatformManual/ProcessConfiguration/ProcessConfiguration.xsd";
String xslFilePath="file:///D:/workspaces/mtplatform/PlatformManual_V1/PlatformManual/ProcessConfiguration/ProcessConfiguration.xsl";
Processor processor=new Processor(false);
XdmNode node=processor.newDocumentBuilder().build(new File(new URI(xsdFilePath)));
XsltCompiler xsltCompiler=processor.newXsltCompiler();
//xsltCompiler.setParameter(new QName("delegateGroupName"), XdmValue.makeValue("imapAttachmentDownloaderGroup"));
StreamSource xsdSource=new StreamSource(new FileInputStream(new File(new URI(xsdFilePath))));
StreamSource xslSource=new StreamSource(new FileInputStream(new File(new URI(xslFilePath))));
XsltExecutable compiledXSL=xsltCompiler.compile(xslSource);
Xslt30Transformer xslTransformer=compiledXSL.load30();
HashMap<QName, XdmValue> parameterMap=new HashMap<>();
parameterMap.put(new QName("delegateGroupName"), XdmValue.makeValue("imapAttachmentDownloaderGroup"));
xslTransformer.setStylesheetParameters(parameterMap);
XdmValue output=xslTransformer.applyTemplates(node);
System.out.println(output.toString());
xml xslt xsd saxon
I am trying to transform an XML schema with XSLT 3.0 with Saxon 9.9 HE into a JSON. The transformation is working. However, when I output the value of an attribute it is coming with a line break before and after the name. The XSD fragment is below:
<group name="imapAttachmentDownloaderGroup">
<annotation>
<documentation>
Configuration block definitions for IMAP attachment downloader delegate. It contains all the configuration
block definitions that are required to configure the delegate successfully.
</documentation>
</annotation>
<sequence>
<element name="IMAPConnectorConfig">
<complexType>
<attribute name="imapHost" use="required" type="string">
<annotation>
<documentation>
This configuration block deals with the IMAP server name or IP address to where the
connection is to be made to download the attachments.
Example: "outlook.office365.com" or "40.100.137.66"
</documentation>
</annotation>
</attribute>
<attribute name="imapPort" use="required" type="int">
<annotation>
<documentation>
The port to use to connect to the server, defaults to 993.
Example: "993"
</documentation>
</annotation>
</attribute>
....
The SXL is as below:
<?xml version="1.0" encoding="UTF-8"?>
<stylesheet version="3.0"
xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.proviseconsulting.com/ProcessConfig"
xmlns:saxon="http://saxon.sf.net/"
xsi:schemaLocation="http://www.w3.org/1999/XSL/Transform
https://www.w3.org/2007/schema-for-xslt20.xsd">
<mode on-no-match="shallow-skip"/>
<output method="text" encoding="utf-8" indent="no" media-type="application/json" normalization-form="true"/>
<strip-space elements="*" />
<!-- <template match="text()|@*"/> -->
<param name="delegateGroupName" required="yes"/>
<template match="/child::xsi:schema/child::xsi:group[attribute::name=$delegateGroupName]">
<variable name="xx" select="attribute::name"/>
{'groupName':'<value-of select="normalize-space($xx)"/>'
<for-each select="child::xsi:sequence/child::xsi:element">
,'<value-of select="attribute::name"/>':{
<for-each select="child::xsi:complexType/child::xsi:attribute">
<choose>
<when test="position()=last()">'name':'<value-of select="attribute::name"/>'</when>
<otherwise>'name':'<value-of select="attribute::name"/>',</otherwise>
</choose>
</for-each>
<for-each select="child::xsi:complexType/child::xsi:attributeGroup">
<value-of select="attribute::ref"/>
</for-each>
}
</for-each>
}
<!-- <apply-templates select="attribute::name"/> -->
</template>
The output is:
{'groupName':'
imapAttachmentDownloaderGroup
'
, '
IMAPConnectorConfig
':{
'name':'
imapHost
',
'name':'
imapPort
',
'name':'
sslEnabled
',
'name':'
startTLSEnabled
',
'name':'
imapUser
',
'name':'
imapPassword
',
'name':'
credentialId
I have tried all the mechanisms that I could find in the posts assigning it to variable, normalize-space, normalize-space with string() with data(). Nothing seems to be working. Any help would be sincerely appreciated.
=== Including complete example ===
XSL (removed all the comments and other elements):
<?xml version="1.0" encoding="UTF-8"?>
<stylesheet version="3.0"
xmlns="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.proviseconsulting.com/ProcessConfig"
xmlns:saxon="http://saxon.sf.net/"
xsi:schemaLocation="http://www.w3.org/1999/XSL/Transform
https://www.w3.org/2007/schema-for-xslt20.xsd">
<mode on-no-match="shallow-skip"/>
<output method="text" encoding="utf-8" indent="no" media-type="application/json" normalization-form="true"/>
<strip-space elements="*" />
<param name="delegateGroupName" required="yes"/>
<template match="/child::xsi:schema/child::xsi:group[attribute::name=$delegateGroupName]">
<text>{"groupName":"</text><value-of select="attribute::name/normalize-space()"/><text>"}</text>
</template>
=== Output ===
{"groupName":"
imapAttachmentDownloaderGroup
"}
The input XSD remains the same. The Java code is as below:
String xsdFilePath="file:///D:/workspaces/mtplatform/PlatformManual_V1/PlatformManual/ProcessConfiguration/ProcessConfiguration.xsd";
String xslFilePath="file:///D:/workspaces/mtplatform/PlatformManual_V1/PlatformManual/ProcessConfiguration/ProcessConfiguration.xsl";
Processor processor=new Processor(false);
XdmNode node=processor.newDocumentBuilder().build(new File(new URI(xsdFilePath)));
XsltCompiler xsltCompiler=processor.newXsltCompiler();
//xsltCompiler.setParameter(new QName("delegateGroupName"), XdmValue.makeValue("imapAttachmentDownloaderGroup"));
StreamSource xsdSource=new StreamSource(new FileInputStream(new File(new URI(xsdFilePath))));
StreamSource xslSource=new StreamSource(new FileInputStream(new File(new URI(xslFilePath))));
XsltExecutable compiledXSL=xsltCompiler.compile(xslSource);
Xslt30Transformer xslTransformer=compiledXSL.load30();
HashMap<QName, XdmValue> parameterMap=new HashMap<>();
parameterMap.put(new QName("delegateGroupName"), XdmValue.makeValue("imapAttachmentDownloaderGroup"));
xslTransformer.setStylesheetParameters(parameterMap);
XdmValue output=xslTransformer.applyTemplates(node);
System.out.println(output.toString());
xml xslt xsd saxon
xml xslt xsd saxon
edited Nov 19 at 14:39
asked Nov 19 at 13:35
Ironluca
1,44211226
1,44211226
You can use<xsl:text>':{</xsl:text>
to make sure you only explicitly output that text and not the line break your current code also includes. However, given that you use XSLT 3 and want JSON output it seems more adequate to use theoutput method="json"
and have the code create the necessary XPath 3.1 map structure.
– Martin Honnen
Nov 19 at 13:48
@MartinHonnen, as suggested tried <text>{'groupName':'</text><value-of select="attribute::name"/><text>'</text> it is still giving the same output wil line breaks ... any help would be appreciated, thanks
– Ironluca
Nov 19 at 14:12
Consider to post minimal but complete samples to allow us to reproduce the problem. When I try to apply my suggestion at xsltfiddle.liberty-development.net/gWmuiKm/1 I get the attribute names on one line'IMAPConnectorConfig':{'name':'imapHost','name':'imapPort'
. Not sure however what kind of JSON that would be with two properties of the same namename
.
– Martin Honnen
Nov 19 at 14:26
As for my suggestion to use output methodjson
and construct XPath 3.1 maps, see xsltfiddle.liberty-development.net/gWmuiKm. I had to adjust the structure to make sense as JSON as having several"name" : "..."
doesn't seem to make sense if JSON is really the target format.
– Martin Honnen
Nov 19 at 14:26
1
Does that attributenormalization-form="true"
onxsl:output
really work for you? It would really help if you post minimal but complete samples to allow others to run the sample to easily reproduce the problem, don't see why we need to have to complete schemas or stylesheet code. Also try running from the command line first. If you want thexsl:output
to have any effect I don't understand why you use the overload ofapplyTemplates
returning a raw result, seems better to use a Destination where serialization happens.
– Martin Honnen
Nov 19 at 16:12
|
show 3 more comments
You can use<xsl:text>':{</xsl:text>
to make sure you only explicitly output that text and not the line break your current code also includes. However, given that you use XSLT 3 and want JSON output it seems more adequate to use theoutput method="json"
and have the code create the necessary XPath 3.1 map structure.
– Martin Honnen
Nov 19 at 13:48
@MartinHonnen, as suggested tried <text>{'groupName':'</text><value-of select="attribute::name"/><text>'</text> it is still giving the same output wil line breaks ... any help would be appreciated, thanks
– Ironluca
Nov 19 at 14:12
Consider to post minimal but complete samples to allow us to reproduce the problem. When I try to apply my suggestion at xsltfiddle.liberty-development.net/gWmuiKm/1 I get the attribute names on one line'IMAPConnectorConfig':{'name':'imapHost','name':'imapPort'
. Not sure however what kind of JSON that would be with two properties of the same namename
.
– Martin Honnen
Nov 19 at 14:26
As for my suggestion to use output methodjson
and construct XPath 3.1 maps, see xsltfiddle.liberty-development.net/gWmuiKm. I had to adjust the structure to make sense as JSON as having several"name" : "..."
doesn't seem to make sense if JSON is really the target format.
– Martin Honnen
Nov 19 at 14:26
1
Does that attributenormalization-form="true"
onxsl:output
really work for you? It would really help if you post minimal but complete samples to allow others to run the sample to easily reproduce the problem, don't see why we need to have to complete schemas or stylesheet code. Also try running from the command line first. If you want thexsl:output
to have any effect I don't understand why you use the overload ofapplyTemplates
returning a raw result, seems better to use a Destination where serialization happens.
– Martin Honnen
Nov 19 at 16:12
You can use
<xsl:text>':{</xsl:text>
to make sure you only explicitly output that text and not the line break your current code also includes. However, given that you use XSLT 3 and want JSON output it seems more adequate to use the output method="json"
and have the code create the necessary XPath 3.1 map structure.– Martin Honnen
Nov 19 at 13:48
You can use
<xsl:text>':{</xsl:text>
to make sure you only explicitly output that text and not the line break your current code also includes. However, given that you use XSLT 3 and want JSON output it seems more adequate to use the output method="json"
and have the code create the necessary XPath 3.1 map structure.– Martin Honnen
Nov 19 at 13:48
@MartinHonnen, as suggested tried <text>{'groupName':'</text><value-of select="attribute::name"/><text>'</text> it is still giving the same output wil line breaks ... any help would be appreciated, thanks
– Ironluca
Nov 19 at 14:12
@MartinHonnen, as suggested tried <text>{'groupName':'</text><value-of select="attribute::name"/><text>'</text> it is still giving the same output wil line breaks ... any help would be appreciated, thanks
– Ironluca
Nov 19 at 14:12
Consider to post minimal but complete samples to allow us to reproduce the problem. When I try to apply my suggestion at xsltfiddle.liberty-development.net/gWmuiKm/1 I get the attribute names on one line
'IMAPConnectorConfig':{'name':'imapHost','name':'imapPort'
. Not sure however what kind of JSON that would be with two properties of the same name name
.– Martin Honnen
Nov 19 at 14:26
Consider to post minimal but complete samples to allow us to reproduce the problem. When I try to apply my suggestion at xsltfiddle.liberty-development.net/gWmuiKm/1 I get the attribute names on one line
'IMAPConnectorConfig':{'name':'imapHost','name':'imapPort'
. Not sure however what kind of JSON that would be with two properties of the same name name
.– Martin Honnen
Nov 19 at 14:26
As for my suggestion to use output method
json
and construct XPath 3.1 maps, see xsltfiddle.liberty-development.net/gWmuiKm. I had to adjust the structure to make sense as JSON as having several "name" : "..."
doesn't seem to make sense if JSON is really the target format.– Martin Honnen
Nov 19 at 14:26
As for my suggestion to use output method
json
and construct XPath 3.1 maps, see xsltfiddle.liberty-development.net/gWmuiKm. I had to adjust the structure to make sense as JSON as having several "name" : "..."
doesn't seem to make sense if JSON is really the target format.– Martin Honnen
Nov 19 at 14:26
1
1
Does that attribute
normalization-form="true"
on xsl:output
really work for you? It would really help if you post minimal but complete samples to allow others to run the sample to easily reproduce the problem, don't see why we need to have to complete schemas or stylesheet code. Also try running from the command line first. If you want the xsl:output
to have any effect I don't understand why you use the overload of applyTemplates
returning a raw result, seems better to use a Destination where serialization happens.– Martin Honnen
Nov 19 at 16:12
Does that attribute
normalization-form="true"
on xsl:output
really work for you? It would really help if you post minimal but complete samples to allow others to run the sample to easily reproduce the problem, don't see why we need to have to complete schemas or stylesheet code. Also try running from the command line first. If you want the xsl:output
to have any effect I don't understand why you use the overload of applyTemplates
returning a raw result, seems better to use a Destination where serialization happens.– Martin Honnen
Nov 19 at 16:12
|
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
In general, to control the text output, you can use the xsl:text
element https://www.w3.org/TR/xslt-30/#xsl-text in the form
<for-each select="child::xsi:sequence/child::xsi:element">
<text>,'</text>
<value-of select="attribute::name"/>
<text>':{</text>
Furthermore, if you use Xslt30Transformer
and want a serialized result in the form of text, like JSON, where the format is defined by the xsl:output
in your XSLT, then you should use an overload of applyTemplates
allowing you to use a Serializer
as the Destination, i.e. http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#applyTemplates-net.sf.saxon.s9api.XdmValue-net.sf.saxon.s9api.Destination- with a Serializer
created by the Xslt30Transformer
(http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#newSerializer-java.io.OutputStream-), so in the simple case of testing the result with System.out you would use
Serializer serializer = xslTransformer.newSerializer(System.out);
xslTransformer.applyTemplates(node, serializer);
In your Java case you have used the overload to create an XdmValue
, take notice that its documentation http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#applyTemplates-net.sf.saxon.s9api.XdmValue- says it returns
the raw result of applying templates to the supplied selection value,
without wrapping in a document node or serializing the result
As you have found according to your comments, if you have an XdmValue
and want to serialize it in a controlled way, you are better off using the serializeXdmValue
method of a Serializer
set up as needed instead of simply calling toString
on the XdmValue
.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
In general, to control the text output, you can use the xsl:text
element https://www.w3.org/TR/xslt-30/#xsl-text in the form
<for-each select="child::xsi:sequence/child::xsi:element">
<text>,'</text>
<value-of select="attribute::name"/>
<text>':{</text>
Furthermore, if you use Xslt30Transformer
and want a serialized result in the form of text, like JSON, where the format is defined by the xsl:output
in your XSLT, then you should use an overload of applyTemplates
allowing you to use a Serializer
as the Destination, i.e. http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#applyTemplates-net.sf.saxon.s9api.XdmValue-net.sf.saxon.s9api.Destination- with a Serializer
created by the Xslt30Transformer
(http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#newSerializer-java.io.OutputStream-), so in the simple case of testing the result with System.out you would use
Serializer serializer = xslTransformer.newSerializer(System.out);
xslTransformer.applyTemplates(node, serializer);
In your Java case you have used the overload to create an XdmValue
, take notice that its documentation http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#applyTemplates-net.sf.saxon.s9api.XdmValue- says it returns
the raw result of applying templates to the supplied selection value,
without wrapping in a document node or serializing the result
As you have found according to your comments, if you have an XdmValue
and want to serialize it in a controlled way, you are better off using the serializeXdmValue
method of a Serializer
set up as needed instead of simply calling toString
on the XdmValue
.
add a comment |
up vote
1
down vote
accepted
In general, to control the text output, you can use the xsl:text
element https://www.w3.org/TR/xslt-30/#xsl-text in the form
<for-each select="child::xsi:sequence/child::xsi:element">
<text>,'</text>
<value-of select="attribute::name"/>
<text>':{</text>
Furthermore, if you use Xslt30Transformer
and want a serialized result in the form of text, like JSON, where the format is defined by the xsl:output
in your XSLT, then you should use an overload of applyTemplates
allowing you to use a Serializer
as the Destination, i.e. http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#applyTemplates-net.sf.saxon.s9api.XdmValue-net.sf.saxon.s9api.Destination- with a Serializer
created by the Xslt30Transformer
(http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#newSerializer-java.io.OutputStream-), so in the simple case of testing the result with System.out you would use
Serializer serializer = xslTransformer.newSerializer(System.out);
xslTransformer.applyTemplates(node, serializer);
In your Java case you have used the overload to create an XdmValue
, take notice that its documentation http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#applyTemplates-net.sf.saxon.s9api.XdmValue- says it returns
the raw result of applying templates to the supplied selection value,
without wrapping in a document node or serializing the result
As you have found according to your comments, if you have an XdmValue
and want to serialize it in a controlled way, you are better off using the serializeXdmValue
method of a Serializer
set up as needed instead of simply calling toString
on the XdmValue
.
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
In general, to control the text output, you can use the xsl:text
element https://www.w3.org/TR/xslt-30/#xsl-text in the form
<for-each select="child::xsi:sequence/child::xsi:element">
<text>,'</text>
<value-of select="attribute::name"/>
<text>':{</text>
Furthermore, if you use Xslt30Transformer
and want a serialized result in the form of text, like JSON, where the format is defined by the xsl:output
in your XSLT, then you should use an overload of applyTemplates
allowing you to use a Serializer
as the Destination, i.e. http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#applyTemplates-net.sf.saxon.s9api.XdmValue-net.sf.saxon.s9api.Destination- with a Serializer
created by the Xslt30Transformer
(http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#newSerializer-java.io.OutputStream-), so in the simple case of testing the result with System.out you would use
Serializer serializer = xslTransformer.newSerializer(System.out);
xslTransformer.applyTemplates(node, serializer);
In your Java case you have used the overload to create an XdmValue
, take notice that its documentation http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#applyTemplates-net.sf.saxon.s9api.XdmValue- says it returns
the raw result of applying templates to the supplied selection value,
without wrapping in a document node or serializing the result
As you have found according to your comments, if you have an XdmValue
and want to serialize it in a controlled way, you are better off using the serializeXdmValue
method of a Serializer
set up as needed instead of simply calling toString
on the XdmValue
.
In general, to control the text output, you can use the xsl:text
element https://www.w3.org/TR/xslt-30/#xsl-text in the form
<for-each select="child::xsi:sequence/child::xsi:element">
<text>,'</text>
<value-of select="attribute::name"/>
<text>':{</text>
Furthermore, if you use Xslt30Transformer
and want a serialized result in the form of text, like JSON, where the format is defined by the xsl:output
in your XSLT, then you should use an overload of applyTemplates
allowing you to use a Serializer
as the Destination, i.e. http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#applyTemplates-net.sf.saxon.s9api.XdmValue-net.sf.saxon.s9api.Destination- with a Serializer
created by the Xslt30Transformer
(http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#newSerializer-java.io.OutputStream-), so in the simple case of testing the result with System.out you would use
Serializer serializer = xslTransformer.newSerializer(System.out);
xslTransformer.applyTemplates(node, serializer);
In your Java case you have used the overload to create an XdmValue
, take notice that its documentation http://saxonica.com/html/documentation/javadoc/net/sf/saxon/s9api/Xslt30Transformer.html#applyTemplates-net.sf.saxon.s9api.XdmValue- says it returns
the raw result of applying templates to the supplied selection value,
without wrapping in a document node or serializing the result
As you have found according to your comments, if you have an XdmValue
and want to serialize it in a controlled way, you are better off using the serializeXdmValue
method of a Serializer
set up as needed instead of simply calling toString
on the XdmValue
.
answered Nov 19 at 21:04
Martin Honnen
110k65876
110k65876
add a comment |
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53375803%2fxslt-unable-to-remove-line-break-before-and-after-attribute-value%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 can use
<xsl:text>':{</xsl:text>
to make sure you only explicitly output that text and not the line break your current code also includes. However, given that you use XSLT 3 and want JSON output it seems more adequate to use theoutput method="json"
and have the code create the necessary XPath 3.1 map structure.– Martin Honnen
Nov 19 at 13:48
@MartinHonnen, as suggested tried <text>{'groupName':'</text><value-of select="attribute::name"/><text>'</text> it is still giving the same output wil line breaks ... any help would be appreciated, thanks
– Ironluca
Nov 19 at 14:12
Consider to post minimal but complete samples to allow us to reproduce the problem. When I try to apply my suggestion at xsltfiddle.liberty-development.net/gWmuiKm/1 I get the attribute names on one line
'IMAPConnectorConfig':{'name':'imapHost','name':'imapPort'
. Not sure however what kind of JSON that would be with two properties of the same namename
.– Martin Honnen
Nov 19 at 14:26
As for my suggestion to use output method
json
and construct XPath 3.1 maps, see xsltfiddle.liberty-development.net/gWmuiKm. I had to adjust the structure to make sense as JSON as having several"name" : "..."
doesn't seem to make sense if JSON is really the target format.– Martin Honnen
Nov 19 at 14:26
1
Does that attribute
normalization-form="true"
onxsl:output
really work for you? It would really help if you post minimal but complete samples to allow others to run the sample to easily reproduce the problem, don't see why we need to have to complete schemas or stylesheet code. Also try running from the command line first. If you want thexsl:output
to have any effect I don't understand why you use the overload ofapplyTemplates
returning a raw result, seems better to use a Destination where serialization happens.– Martin Honnen
Nov 19 at 16:12