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









share|improve this question
























  • 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












  • 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






  • 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

















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









share|improve this question
























  • 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












  • 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






  • 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















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









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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












  • 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






  • 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




















  • 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












  • 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






  • 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


















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














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.






share|improve this answer





















    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',
    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%2f53375803%2fxslt-unable-to-remove-line-break-before-and-after-attribute-value%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    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.






    share|improve this answer

























      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.






      share|improve this answer























        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.






        share|improve this answer












        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 at 21:04









        Martin Honnen

        110k65876




        110k65876






























            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.





            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.




            draft saved


            draft discarded














            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





















































            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

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            Origin of the phrase “under your belt”?