Can I use text file as primary input of XSLT?
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 22
- Joined: Tue Oct 17, 2017 5:05 pm
Can I use text file as primary input of XSLT?
Post by serioadamo97 »
I want to use a text file as primary input.
For example:
In XSLT debugger perspective view, select XML: mytext.txt, select XSLT: myT2X.xsl.
myT2X.xsl is :
When I run the debugger, the following error occured:
E Content is not allowed in prolog.
F Content is not allowed in prolog.
F Content is not allowed in prolog.
I can use unparsed-text() to read .txt in stylesheet, but how to use txt file as primary input directly?
Thanks in advance.
For example:
In XSLT debugger perspective view, select XML: mytext.txt, select XSLT: myT2X.xsl.
myT2X.xsl is :
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="/text()">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
E Content is not allowed in prolog.
F Content is not allowed in prolog.
F Content is not allowed in prolog.
I can use unparsed-text() to read .txt in stylesheet, but how to use txt file as primary input directly?
Thanks in advance.
-
- Posts: 9439
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Can I use text file as primary input of XSLT?
Hi,
XSLT needs to be applied over XML content, even if inside it reads a separate text file and uses only that text file contents.
In XSLT 3.0 they added a feature called "initial template". You specify in the transformation scenario that a certain named template is your initial template and you no longer need to provide an input XML to the XSLT:
https://www.oxygenxml.com/doc/versions/ ... hing2.html
Regards,
Radu
XSLT needs to be applied over XML content, even if inside it reads a separate text file and uses only that text file contents.
In XSLT 3.0 they added a feature called "initial template". You specify in the transformation scenario that a certain named template is your initial template and you no longer need to provide an input XML to the XSLT:
https://www.oxygenxml.com/doc/versions/ ... hing2.html
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 22
- Joined: Tue Oct 17, 2017 5:05 pm
Re: Can I use text file as primary input of XSLT?
Post by serioadamo97 »
Thanks Radu.Radu wrote:Hi,
XSLT needs to be applied over XML content, even if inside it reads a separate text file and uses only that text file contents.
In XSLT 3.0 they added a feature called "initial template". You specify in the transformation scenario that a certain named template is your initial template and you no longer need to provide an input XML to the XSLT:
But initial template still make stylesheet(eg: myT2X.xsl) depends on specific input file name (eg: myText.txt).
Is there another way to workround? (make a pure text file as primary input)
Because pure text is a legal XDM tree model (although it is not well-formed xml).
-
- Posts: 9439
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Can I use text file as primary input of XSLT?
Hi,
In my opinion what you want is not possible.
If you want there is a Saxon XSLT processor users list:
https://sourceforge.net/p/saxon/mailman/saxon-help/
where you can register and ask this. But as far as I know the processor will not receive text content as input.
What you could probably do would be to use an xsl:param to pass the path to the text file to the XSLT stylesheet, so that the stylesheet is not hardcoded looking at a certain text file.
Regards,
Radu
In my opinion what you want is not possible.
If you want there is a Saxon XSLT processor users list:
https://sourceforge.net/p/saxon/mailman/saxon-help/
where you can register and ask this. But as far as I know the processor will not receive text content as input.
What you could probably do would be to use an xsl:param to pass the path to the text file to the XSLT stylesheet, so that the stylesheet is not hardcoded looking at a certain text file.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 6
- Joined: Wed Aug 09, 2006 1:03 pm
Re: Can I use text file as primary input of XSLT?
at: serioadamo97
I would like to ask if you found a solution to get a plain text file as primary input file for XSLT transformation (also in Oxygen)?
Many thanks in advance and best regards,
I would like to ask if you found a solution to get a plain text file as primary input file for XSLT transformation (also in Oxygen)?
Many thanks in advance and best regards,
-
- Posts: 9439
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Can I use text file as primary input of XSLT?
Hi,
There is no way to do this with XSLT, the XSLT templates are applied directly on XML elements and you can only load other files using the "unparsed-text" function:
https://stackoverflow.com/questions/159 ... -with-xslt
Regards,
Radu
There is no way to do this with XSLT, the XSLT templates are applied directly on XML elements and you can only load other files using the "unparsed-text" function:
https://stackoverflow.com/questions/159 ... -with-xslt
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 6
- Joined: Wed Aug 09, 2006 1:03 pm
Re: Can I use text file as primary input of XSLT?
Hello Radu
Many thanks for your hints. Practically for oXygen there is needed an source/input XML document. This can be simple as:
and the XSLT template starts with:
best regards,
André
Many thanks for your hints. Practically for oXygen there is needed an source/input XML document. This can be simple as:
Code: Select all
<text2xml></text2xml>
Code: Select all
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:variable name="vText" select=
"unparsed-text('new.txt')"/>
<xsl:variable name="vLines" select=
"tokenize($vText, '
?
')[normalize-space()]"/>
<xsl:template match="/">
<xsl:for-each select="$vLines">
...
André
-
- Posts: 9439
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Can I use text file as primary input of XSLT?
Hi André,
Thanks for posting the sample XSLT content. This limitation of having an XML input is not imposed implicitly by Oxygen but by the XSLT standard.
In such cases you can use as XML source even the XSLT stylesheet if you do not want to have a blank XML document lying around on the hard drive.
Regards,
Radu
Thanks for posting the sample XSLT content. This limitation of having an XML input is not imposed implicitly by Oxygen but by the XSLT standard.
In such cases you can use as XML source even the XSLT stylesheet if you do not want to have a blank XML document lying around on the hard drive.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service