Click here to Skip to main content
14,774,187 members
Home » Discussions » XML / XSL
   

XML / XSL

 
QuestionXSL to get only elements which have no childs Pin
MrKBA19-Sep-17 1:26
MemberMrKBA19-Sep-17 1:26 
AnswerRe: XSL to get only elements which have no childs Pin
Richard Deeming19-Sep-17 3:15
mveRichard Deeming19-Sep-17 3:15 
GeneralRe: XSL to get only elements which have no childs Pin
MrKBA19-Sep-17 4:02
MemberMrKBA19-Sep-17 4:02 
Questionshare me best practices to enhance xslt related functionality in production Pin
Member 1178590912-Jul-17 2:50
MemberMember 1178590912-Jul-17 2:50 
AnswerRe: share me best practices to enhance xslt related functionality in production Pin
Richard MacCutchan12-Jul-17 4:58
mveRichard MacCutchan12-Jul-17 4:58 
GeneralRe: share me best practices to enhance xslt related functionality in production Pin
jschell1-Sep-17 13:24
Memberjschell1-Sep-17 13:24 
GeneralRe: share me best practices to enhance xslt related functionality in production Pin
Richard MacCutchan1-Sep-17 22:42
mveRichard MacCutchan1-Sep-17 22:42 
QuestionTransform XML Pin
TML6-Jul-17 10:15
MemberTML6-Jul-17 10:15 
I am trying to transform an XML file through code using XSL, but for some reason, the file output is displaying the entire XML as a string at the top of the document and then, just under the XML string, the document is parsed correctly by the XSL stylesheet. I would like to learn why this is happening. Here is the VB transform code:

        Dim ds As New DataSet
        ds.ReadXml(Server.MapPath("FormResults/" & FormID.ToString() & ".xml"))


        Dim DocXSL As New XslCompiledTransform
        Dim sw As New StringWriter()
        ds.WriteXml(sw)
        ds.Dispose()

        Dim DocXML As New XmlDocument
        DocXML.LoadXml(sw.ToString())


        'The GetXSLContent function returns the XLS template to be used
        DocXSL.Load(GetXSLContent(DFLID))
        DocXSL.Transform(DocXML, Nothing, sw)
        Dim result As String = sw.ToString()
        sw.Close()
        sw = Nothing

Me.My_Literal.Text = result.ToString()


    Private Function GetXSLContent(ByVal DFLID As Integer) As String
        Dim str As String = String.Empty
        str = Server.MapPath("FormLetters/" & DFLID.ToString() & "_DataTemplate.xslt")
        Return str
    End Function


Here is the XML

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Results>
  <Fields ID="48">
    <Department>I.T.</Department>
    <Extension>2267</Extension>
    <Location>Primary Office Bldg</Location>
    <Name_of_User>David</Name_of_User>
    <Date>9/12/2014</Date>
    <Time>04:49</Time>
    <Details1>This is a test. asdf sasdf sa</Details1>
    <Details2>This is only a test.</Details2>
    <Details3>This is a test.</Details3>
    <Details4>This is only a test.</Details4>
    <Details5>This is a test.</Details5>
    <Details6>This is only a test.</Details6>
    <Details7>This is a test.</Details7>
    <Details8>This is only a test.</Details8>
  </Fields>
</Results>


Here is the XSLT

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" encoding="utf-8" omit-xml-declaration="yes"/>
    <xsl:template match="/">
        <div class="rndc" style="left:50%;right:50%;margin:auto;width:90%;border: 1px solid #e0e0e0;padding: 0px 5px 0px 5px">
            <xsl:for-each select="Results/Fields">
                <div style="text-align:left;vertical-align:top;padding: 0px 5px 0px 5px;width:96%;white-space:pre-wrap;display:inline-block">
<table style='border-collapse: collapse; left: 50%; right: 50%; margin: auto; width: 80%'>
    <tr>
        <td class="txtlrg" style="vertical-align:top;text-align:left" colspan="2"> <xsl:value-of select="Department"/> </td>
    </tr>
    <tr>
        <td style="vertical-align:top;text-align:right">User Name:</td>
        <td><xsl:value-of select="Name_of_User"/></td>
    </tr>
    <tr>
        <td style="vertical-align:top;text-align:right">Extension:</td>
        <td><xsl:value-of select="Extension"/></td>
    </tr>
    <tr>
        <td style="vertical-align:top;text-align:right">Location:</td>
        <td><xsl:value-of select="Location"/></td>
    </tr>
    <tr>
        <td style="vertical-align:top;text-align:right">Date & Time:</td>
        <td style="white-space:pre"><xsl:value-of select="Date"/> <xsl:value-of select="Time"/></td>
    </tr>
    <tr>
        <td style="vertical-align:top;text-align:right">Details:</td>
        <td style="white-space:pre"><xsl:value-of select="Details1"/><br />
        <xsl:value-of select="Details2"/><br />
        <xsl:value-of select="Details3"/><br />
        <xsl:value-of select="Details4"/><br />
        <xsl:value-of select="Details5"/></td>
    </tr>
</table>                </div>
                <div style="page-break-before: always;"></div>
            </xsl:for-each>
        </div>
    </xsl:template>
</xsl:stylesheet>


Here's the output:
I.T. 2267 Gov. Center Vickie 9/12/2014 04:49 This is a test. asdf sasdf sa This is only a test. This is a test. This is only a test. This is a test. This is only a test. This is a test. This is only a test.

I.T.
User Name: David
Extension: 2267
Location: Primary Office Bldg
Date & Time: 9/12/2014 04:49
Details: This is a test. asdf sasdf sa
This is only a test.
This is a test.
This is only a test.
This is a test.


Thanks in advance!
AnswerRe: Transform XML Pin
Richard Deeming6-Jul-17 11:40
mveRichard Deeming6-Jul-17 11:40 
AnswerRe: Transform XML Pin
TML6-Jul-17 11:50
MemberTML6-Jul-17 11:50 
Questionsaving a file to the internet. Pin
felixjrz198531-May-17 22:54
Memberfelixjrz198531-May-17 22:54 
SuggestionRe: saving a file to the internet. Pin
Richard MacCutchan31-May-17 23:32
mveRichard MacCutchan31-May-17 23:32 
GeneralRe: saving a file to the internet. Pin
felixjrz19851-Jun-17 1:43
Memberfelixjrz19851-Jun-17 1:43 
GeneralRe: saving a file to the internet. Pin
Richard MacCutchan1-Jun-17 2:03
mveRichard MacCutchan1-Jun-17 2:03 
GeneralRe: saving a file to the internet. Pin
Gerry Schmitz1-Jun-17 4:20
mveGerry Schmitz1-Jun-17 4:20 
AnswerRe: saving a file to the internet. Pin
Terry Perez11-Sep-17 4:41
MemberTerry Perez11-Sep-17 4:41 
QuestionXSLT passing a variable to starts-with Pin
bjmallon13-Feb-17 15:03
Memberbjmallon13-Feb-17 15:03 
AnswerRe: XSLT passing a variable to starts-with Pin
Richard Deeming14-Feb-17 3:32
mveRichard Deeming14-Feb-17 3:32 
GeneralRe: XSLT passing a variable to starts-with Pin
bjmallon16-Feb-17 19:45
Memberbjmallon16-Feb-17 19:45 
GeneralRe: XSLT passing a variable to starts-with Pin
Richard Deeming17-Feb-17 2:48
mveRichard Deeming17-Feb-17 2:48 
GeneralRe: XSLT passing a variable to starts-with Pin
bjmallon20-Feb-17 23:55
Memberbjmallon20-Feb-17 23:55 
GeneralRe: XSLT passing a variable to starts-with Pin
Richard Deeming21-Feb-17 2:42
mveRichard Deeming21-Feb-17 2:42 
GeneralRe: XSLT passing a variable to starts-with Pin
bjmallon21-Feb-17 11:24
Memberbjmallon21-Feb-17 11:24 
QuestionHow to generate XML file with serialisation in vb.net Pin
Member 1280320219-Oct-16 9:06
MemberMember 1280320219-Oct-16 9:06 
Rant[REPOST] How to generate XML file with serialisation in vb.net Pin
Richard Deeming19-Oct-16 10:28
mveRichard Deeming19-Oct-16 10:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.