1

Topic: XSLT TXT 2 XML

Good evening!
Let there is a text file:

Name: Value 1
UID: Value 2
Type: Value 3

I want to receive XML:

<Properties the Name = "Value 1" UID = "Value 2" Type = "Value 3">

I do so:

<? 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:output method = "xml" encoding = "UTF-16" indent = "no" omit-xml-declaration = "yes"/>
<xsl:strip-space elements = "*"/>
<xsl:param name = "txt-encoding" as = "xs:string" select = "'CP866 '"/>
<xsl:param name = "txt-uri" as = "xs:string" select = "'file:///D:/2/003610.VR1 '"/>
<xsl:template match = "/">
<xsl:variable name = "txt" select = "unparsed-text ($txt-uri, $txt-encoding)"/>
<xsl:analyze-string select = "$ txt" regex = "\r\n">
<xsl:non-matching-substring>
<xsl:variable name = "Name"> <xsl:analyze-string select = "." regex = "^ the Name: (. *)"> <xsl:matching-substring> <xsl:value-of select = "normalize-space (regex-group (1))" /></xsl:matching-substring></xsl:analyze-string></xsl:variable>
<xsl:variable name = "UID"> <xsl:analyze-string select = "." regex = "^ UID:(. *)"> <xsl:matching-substring> <xsl:value-of select = "normalize-space (regex-group (1))" /></xsl:matching-substring></xsl:analyze-string></xsl:variable>
<xsl:variable name = "Type"> <xsl:analyze-string select = "." regex = "^ Type: (. *)"> <xsl:matching-substring> <xsl:value-of select = "normalize-space (regex-group (1))" /></xsl:matching-substring></xsl:analyze-string></xsl:variable>
</xsl:non-matching-substring>
</xsl:analyze-string>
<Properties the Name = "{$ the Name}" UID = "{$ UID}" Type = "$ Type">
</xsl:template>
</xsl:stylesheet>

Also I receive:

 Warning at xsl:variable on line 18 column 55 of test.xslt:
SXWN9001: A variable with no following sibling instructions has no effect

How it is possible to make such conversion?

2

Re: XSLT TXT 2 XML

Well anybody is visible with such did not work.
Admit I received following XML a file:

<Name> Value 1 </a name> <UID> Value 2 </UID> <Type> Value 3 </type>

By means of following conversion:
[spoiler]

<? 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:output method = "xml" encoding = "UTF-16" indent = "no" omit-xml-declaration = "yes"/>
<xsl:strip-space elements = "*"/>
<xsl:param name = "txt-encoding" as = "xs:string" select = "'CP866 '"/>
<xsl:param name = "txt-uri" as = "xs:string" select = "'file:///D:/2/003610.VR1 '"/>
<xsl:template match = "/">
<xsl:variable name = "txt" select = "unparsed-text ($txt-uri, $txt-encoding)"/>
<xsl:variable name = "entries" as = "node () *">
<xsl:analyze-string select = "$ txt" regex = "\r\n">
<xsl:non-matching-substring>
<xsl:analyze-string select = "." regex = "^ the Name: (. *)" ><xsl:matching-substring><><xsl:value-of select = "normalize-space (regex-group (1))" /></></xsl:matching-substring></xsl:analyze-string>
<xsl:analyze-string select = "." regex = "^ UID:(. *)" ><xsl:matching-substring><UID><xsl:value-of select = "normalize-space (regex-group (1))" /></UID></xsl:matching-substring></xsl:analyze-string>
<xsl:analyze-string select = "." regex = "^ Type: (. *)" ><xsl:matching-substring><><xsl:value-of select = "normalize-space (regex-group (1))" /></></xsl:matching-substring></xsl:analyze-string>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:for-each select = "$ entries">
????????????
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

[/spoiler]
Whether it is possible in a cycle

<xsl:for-each select = "$ entries">
????????????
</xsl:for-each>

To receive the format necessary to me

<Properties the Name = "Value 1" UID = "Value 2" Type = "Value 3">

?

3

Re: XSLT TXT 2 XML

All. The question is closed.