Click here to Skip to main content
15,883,883 members
Home / Discussions / XML / XSL
   

XML / XSL

 
QuestionXSL to get only elements which have no childs Pin
MrKBA19-Sep-17 0:26
MrKBA19-Sep-17 0:26 
AnswerRe: XSL to get only elements which have no childs Pin
Richard Deeming19-Sep-17 2:15
mveRichard Deeming19-Sep-17 2:15 
GeneralRe: XSL to get only elements which have no childs Pin
MrKBA19-Sep-17 3:02
MrKBA19-Sep-17 3:02 
Questionshare me best practices to enhance xslt related functionality in production Pin
Member 1178590912-Jul-17 1:50
Member 1178590912-Jul-17 1:50 
AnswerRe: share me best practices to enhance xslt related functionality in production Pin
Richard MacCutchan12-Jul-17 3:58
mveRichard MacCutchan12-Jul-17 3:58 
GeneralRe: share me best practices to enhance xslt related functionality in production Pin
jschell1-Sep-17 12:24
jschell1-Sep-17 12:24 
GeneralRe: share me best practices to enhance xslt related functionality in production Pin
Richard MacCutchan1-Sep-17 21:42
mveRichard MacCutchan1-Sep-17 21:42 
QuestionTransform XML Pin
TML6-Jul-17 9:15
TML6-Jul-17 9: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 10:40
mveRichard Deeming6-Jul-17 10:40 
AnswerRe: Transform XML Pin
TML6-Jul-17 10:50
TML6-Jul-17 10:50 
Questionsaving a file to the internet. Pin
felixjrz198531-May-17 21:54
felixjrz198531-May-17 21:54 
SuggestionRe: saving a file to the internet. Pin
Richard MacCutchan31-May-17 22:32
mveRichard MacCutchan31-May-17 22:32 
GeneralRe: saving a file to the internet. Pin
felixjrz19851-Jun-17 0:43
felixjrz19851-Jun-17 0:43 
GeneralRe: saving a file to the internet. Pin
Richard MacCutchan1-Jun-17 1:03
mveRichard MacCutchan1-Jun-17 1:03 
GeneralRe: saving a file to the internet. Pin
Gerry Schmitz1-Jun-17 3:20
mveGerry Schmitz1-Jun-17 3:20 
AnswerRe: saving a file to the internet. Pin
Terry Perez11-Sep-17 3:41
Terry Perez11-Sep-17 3:41 
QuestionXSLT passing a variable to starts-with Pin
bjmallon13-Feb-17 14:03
bjmallon13-Feb-17 14:03 
AnswerRe: XSLT passing a variable to starts-with Pin
Richard Deeming14-Feb-17 2:32
mveRichard Deeming14-Feb-17 2:32 
GeneralRe: XSLT passing a variable to starts-with Pin
bjmallon16-Feb-17 18:45
bjmallon16-Feb-17 18:45 
GeneralRe: XSLT passing a variable to starts-with Pin
Richard Deeming17-Feb-17 1:48
mveRichard Deeming17-Feb-17 1:48 
GeneralRe: XSLT passing a variable to starts-with Pin
bjmallon20-Feb-17 22:55
bjmallon20-Feb-17 22:55 
GeneralRe: XSLT passing a variable to starts-with Pin
Richard Deeming21-Feb-17 1:42
mveRichard Deeming21-Feb-17 1:42 
GeneralRe: XSLT passing a variable to starts-with Pin
bjmallon21-Feb-17 10:24
bjmallon21-Feb-17 10:24 
QuestionHow to generate XML file with serialisation in vb.net Pin
Member 1280320219-Oct-16 8:06
Member 1280320219-Oct-16 8:06 
Rant[REPOST] How to generate XML file with serialisation in vb.net Pin
Richard Deeming19-Oct-16 9:28
mveRichard Deeming19-Oct-16 9: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.