Link to home
Start Free TrialLog in
Avatar of RobertGeoff
RobertGeoff

asked on

xslt problem

Hello-

I am trying to develop an xslt engine.  However, when I put the raw xml file into the engine, the output is the original/complete xml file.  I was trying to only extract certain data from the original xml file.  The code is below

<xsl:stylesheet version="2.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:fn="http://www.w3.org/2005/xpath-functions"
	xmlns:xdt="http://www.w3.org/2005/xpath-datatypes"
	xmlns:err="http://www.w3.org/2005/xqt-errors"
	exclude-result-prefixes="xs xdt err fn">


	<xsl:output method="xml" indent="yes"/>
	
	<xsl:template match="/">
		
<xsl:value-of select="invention-title"></xsl:value-of>
	
<xsl:value-of select="abstract"></xsl:value-of>


<xsl:value-of select="us-parties/us-applicants/us-applicant"></xsl:value-of>
<xsl:value-of select="us-parties/inventors/inventor"></xsl:value-of>
<xsl:value-of select="us-exemplary-claim"></xsl:value-of>


<xsl:value-of select="us-bibliographic-data-grant/application-reference"></xsl:value-of>
<xsl:value-of select="us-term-of-grant/us-term-of-extension"></xsl:value-of>
<xsl:value-of select="classifications-ipcr/classification-ipcr/section"></xsl:value-of>
<xsl:value-of select="classifications-ipcr/classification-ipcr/class"></xsl:value-of>
	
<xsl:value-of select="classifications-ipcr/classification-ipcr/subclass"></xsl:value-of>
<xsl:value-of select="classifications-ipcr/classification-ipcr/main-group"></xsl:value-of>
<xsl:value-of select="classifications-ipcr/classification-ipcr/subgroup"></xsl:value-of>
<xsl:value-of select="classification-national/main-classification"></xsl:value-of>


<xsl:value-of select="classification-national/further-classification"></xsl:value-of>


<xsl:value-of select="us-field-of-classification-search/classification-national/main-classification"></xsl:value-of>
<xsl:value-of select="drawings/figure"></xsl:value-of>


	</xsl:template>


</xsl:stylesheet>

Open in new window


Do you have any solution, or is there a problem with my code?  Thank you.  Robert
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RobertGeoff
RobertGeoff

ASKER

Thank you for your comments.  While they did not help exactly, because you did not have compete information, I was motivated to go back and re-write the code and now it works well.  Instead of focusing on the values, I focused on copy and for-each.  Robert
Gertone-

As you're an xslt expert, you can help me out with one other thing.  Let me know if I need to formerly post.

I'll incorpoate my xslt engine into a vb(2010) application.  The xslt engine will be located at a specific url.  this will allow me to distibute the application only.

do you have any sample code handy?  i'll start to code later today, but having a good reference is useful.  robert
Hi Robert,

There are some things you need to be aware of.

VB.net does not natvely support XSLT2
so this
<xsl:stylesheet version="2.0"
should be
<xsl:stylesheet version="1.0"
and there are a bunch of functions you then can not use
(likely you don't use them)

I am not a VB.net coder, so basicaly I have no clue how to call an XSLT from a VB.net application
but I usually look around...
maybe this would help
http://stackoverflow.com/questions/1187782/vb-net-apply-xsl-transformation-to-xml-file
Thanks.  That little bit about "1.0" and "2.0" was a big time saver.  RD
Gertone-

FYI, My final code is below.  You may find it useful in the future.  But, I am trouble accessing the XSL from an online server.  I have tried putting in DROPLR, but I keep getting an error message.  Right now, I stuck it on Google, but I'm not sure if this will work.  Do you know of a suitable way to store an XSL file on an online server for access by an application?  Thanks.  Robert

Public Class XSLTform

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim document As XmlDocument
        Dim savefileDialog1 As New SaveFileDialog()
        Dim output As StringWriter
        Dim navigator As XPathNavigator

        document = New XmlDocument()
        document.LoadXml(textbox1.Text)

        'load the stylesheet
        Dim xslt As New XslCompiledTransform()
        xslt.Load("C:\Users\RobertGeoff\Pictures\Patent Pie docs and programs\PatentXSLT.xsl")

        'execute the transformation and output results to a file
        xslt.Transform(textbox1.Text, "Save.Text")

        output = New StringWriter()
        navigator = document.CreateNavigator
        xslt.Transform(navigator, Nothing, output)

        Dim stream As FileStream = _
        New FileStream(savetxt.Text, FileMode.Create)

        Dim writer As StreamWriter = New StreamWriter(stream)
        writer.Write(output.ToString)

        ' close streams
        writer.Close()
        output.Close()

        'upon pressing the transformation button, a dialog to save the file should come up- Cf the savefiledialog sub down below.
        savefileDialog1.ShowDialog()
        savefileDialog1.Title = "Select or Enter Filename"
        savefileDialog1.Filter = "xml Files(*.xml)|*.xml|All Files|*,*"
        savefileDialog1.FilterIndex = 1
        savefileDialog1.RestoreDirectory = True

    End Sub

Open in new window

it all depends on the .net mechanism of resolving the url in the load
it might be that you need to deactivate some security settings
I am afraid this really is a VB.net issue and I recommend that you post a question in the VB.net TA