|
Hi,
Thanks for your information. I will remove this thread.
Regards,
Priya.
|
|
|
|
|
i use this javascript code, but this gives following error:
"'mappedimg' is an unexpected token. Expecting white space. Line 1, position 27."
code is here:
<body onLoad='LoadImgMap('mappedimg','cng');ChangeMappedImgSize('fitinframe','mappedimg');' onResize='LoadImgMap('mappedimg','cng');ChangeMappedImgSize('fitinframe','mappedimg');'>";
thanx in advance
|
|
|
|
|
It's just invalid javascript.
use double quotes!
<body
onLoad='LoadImgMap("mappedimg","cng");ChangeMappedImgSize("fitinframe","mappedimg");'
onResize='LoadImgMap("mappedimg","cng");ChangeMappedImgSize("fitinframe","mappedimg");'>
...
</body>
|
|
|
|
|
Hello,
I have this in my XSD File :
<xs:sequence>
<xs:element ref="Group" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="User" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
I need to disable the order of apparition of these elements ( i.e: if i put the list of User before the list of Group ,the XML is valid and there is no problem )
I hope that my problem is clear and you can help me about this
|
|
|
|
|
Try this...
<xs:choice>
<xs:sequence>
<xs:element ref="Group" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="User" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:sequence>
<xs:element ref="User" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="Group" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:choice>
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
this work, but I have an other problem with this :
The error is :
The element 'IMPORT_USERS' is used but not declared in the DTD/Schema.
To make you in the better situation ;
This is my XSD File:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="IMPORT_USERS">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:element ref="Group" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="User" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:sequence>
<xs:element ref="User" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="Group" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:choice>
<xs:attribute name="XSDversion" use="required">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:enumeration value="1.0"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="Group">
<xs:complexType>
<xs:attribute name="Name" use="required">
<xs:simpleType>
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="Description" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="User">
<xs:complexType>
<xs:attribute name="Name" use="required">
<xs:simpleType>
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="Description" use="optional">
<xs:simpleType>
<xs:restriction base="xs:string"/>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
And this is my XML File
<IMPORT_USERS XSDversion="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Program Files\TEST_XSD.xsd">
<User Name="USER1" Description="user1"/>
<User Name="USER2" Description="user2"/>
<Group Name="GRP_1" Description="Niv 1"/>
<Group Name="GRP_2" Description="Niv 2"/>
</IMPORT_USERS>
Can you help me about this ?
Thank you for Help
|
|
|
|
|
The issue is this block:
<xs:choice>
<xs:sequence>
<xs:element ref="Group" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="User" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:sequence>
<xs:element ref="User" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="Group" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:choice>
Specifically, that everything has a minOccurs of 0. Change it to this:
<xs:choice>
<xs:sequence>
<xs:element ref="Group" minOccurs="1" maxOccurs="unbounded"/>
<xs:element ref="User" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:sequence>
<xs:element ref="User" minOccurs="1" maxOccurs="unbounded"/>
<xs:element ref="Group" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:choice>
That way, the schema processor can determine which branch needs to be followed when validating.
And if you want to allow empty IMPORT_USERS elements, change it to this:
<xs:choice>
<xs:sequence>
<xs:element ref="Group" minOccurs="1" maxOccurs="unbounded"/>
<xs:element ref="User" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:sequence>
<xs:element ref="User" minOccurs="1" maxOccurs="unbounded"/>
<xs:element ref="Group" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:sequence/>
</xs:choice>
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
Hello,
Thank you very much for help.
Rated
|
|
|
|
|
If I have a category, e.g. 'fish' and within that three sub-categories 'fish1', fish2' and 'fish3' is it possible to use XPath in a way to filter 'fish1' and 'fish3'?
I am looking at using XML for in memory representation of data and need to support multiple selection of data types.
Thanks.
|
|
|
|
|
I haven't tested it specifically but you should be able to use this
//fish[fish1 || fish3]
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi
check out below XML
<fish>
<fish1>
<name> f1 </name>
</fish1>
<fish2>
<name> f2 </name>
</fish2>
<fish3>
<name> f3 </name>
</fish3>
</fish>
and you want to select this fish1 and fish3
then use belwo xpath
/fish/*[contains('fish1fish3',name())]
this will give you NodeList which will contain fish1 and fish3 nodes
if your filter includes number of nodes so that writing each name is inefficient then you should use another approach.
|
|
|
|
|
Hi,
I am trying to get list using xpath data[a='1']/a.
Here is the xml
<data>
<a>h</a>
<a>2</a>
<a>56</a>
<a>4</a>
<a>1</a>
</data>
I am not getting desired result say
<a>1</a> node rather that I am getting all the nodes.
We can check xpath from here http://chris.photobooks.com/xml/default.htm[^]
|
|
|
|
|
Your XPath is selecting all 'a' child nodes of the 'data' node that has an 'a' child node with content '1' - the predicate is applied to the 'data' node selection, whereas you want the predicate to be applied to the 'a' node selection. Like this:
data/a[text()='1']
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
Hi Friends,
I want code to convert Excel data to xml using VBA Macros. I have once code which i got from codeproject, its converting well. But when I give space inbetween words in first row(Header part) its giving error. Not only space all special characters. Kindly help. Its very urgent.
Thanks in Advance.
Regards,
Priya.
|
|
|
|
|
Hi Priya,
I'm developping a website for an befriended artist. I've put her concerts and repertoire in two Excel files - easy for her to update - and added one single macro to them that runs several tasks in a row:
- sort the data
- search for duplicates
- rename the files with a date-code (YYMMDD) in the name, what helps for backing-up the data
- convert the data first into XML-format and then into an HTML-table that can be forwarded to people who might be interested in printing the data
- open an form in IE that uploads the files in XML and HTML-formats directly to the server of her website.
As far as I'm aware, I didn't encounter your type of problem.
For your info and hopefully your help, I add the lengthy code hereunder:
Option Explicit
Sub Sort_and_Eliminate_doubles_and_Send()
' This macro is written by Erik van Dyck
'
Dim OldFn, ShortFn As String, NewFn As String, FnRoot As String, DirDest As String, FN As String
Dim rownumber As Integer, colnumber As Integer, n As Integer
Dim MailAd As Variant, RRange As Variant
Dim fso As Object
' Hide screen
Application.DisplayAlerts = False
' Stop "EnableEvents" while making automatic changes
Application.EnableEvents = False
Remplacer_symboles_par_caractères 'remplace "Œ" par "OE", "..." par "etc.", "œ" par "oe"
' Sort
Range("A1").Select 'Select top left corner
Selection.End(xlDown).Select 'Search bottom row
rownumber = ActiveCell.Row 'Remember bottom row
'MsgBox "Bottom row = " & rownumber
Range("A1").Select
Selection.End(xlToRight).Select 'Search most right column
colnumber = ActiveCell.Column
'MsgBox "Most right column = " & colnumber
Range(Cells(1, 1), Cells(rownumber, colnumber)).Sort _
Key1:=Range("A2"), Order1:=xlAscending, _
Key2:=Range("B2"), Order2:=xlAscending, _
Key3:=Range("C2"), Order3:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal, DataOption2:=xlSortNormal
' Identify doubles
n = 2
While Range("A" & n) <> ""
Range("A" & n).Select
If (LCase(Range("A" & n) & Range("B" & n) & Range("C" & n) & Range("D" & n) & Range("E" & n)) = LCase(Range("A" & n - 1) & Range("B" & n - 1) & Range("C" & n - 1) & Range("D" & n - 1) & Range("E" & n - 1))) Then
rownumber = ActiveCell.Row
RRange = "A" & rownumber & ""
Rows(rownumber & ":" & rownumber).Select
Selection.Delete Shift:=xlUp
Range(RRange).Select
MsgBox "Un double est à éliminer à la rangée " & rownumber & "."
End If
n = n + 1
Wend
' Copy without date in name to "My Data Sources"
OldFn = ActiveWorkbook.Name
FnRoot = Left(OldFn, Len(OldFn) - 11)
ShortFn = FnRoot & ".xls"
NewFn = FnRoot & "_" & Format(Date, "yymmdd") & ".xls" ': MsgBox "L'ancien fichier s'appelait " & OldFn & ", la racine en est " & ShortFn & " et le nouveau fichier s'appellera " & NewFn
' MsgBox "Votre ordinateur s'appelle " & """" & Application.UserName & """."
If Application.UserName = "Erik" Then
DirDest = "D:\Web\Ulrike\"
MailAd = Array("ulrike.vancotthem@gmail.com")
End If
If Application.UserName <> "Erik" Then
DirDest = "C:\Documents and Settings\les amoureux\mes documents\mes kikis docs\mon site\tableau concerts\"
' DirDest = "C:\"
MailAd = Array("erik.vandyck@club-internet.fr")
End If
' Re-enable "EnableEvents" after the automatic actions above
Application.EnableEvents = True
' Save updates XLS-file
On Error Resume Next
MkDir DirDest & "Docs\"
FN = DirDest & "docs\" & NewFn
On Error Resume Next
ActiveWorkbook.SaveAs FileName:=FN, ReadOnlyRecommended:=False, AddToMru:=True
Application.DisplayAlerts = True
' Send file by email
On Error Resume Next
Application.Dialogs(xlDialogSendMail).Show MailAd
FN = FnRoot & ".XML"
Make_XML DirDest, FN
FN = FnRoot & ".HTML"
Make_HTML DirDest, FN
' Prepare uploading
MsgBox "Téléchargez en un coup" & Chr(10) & Chr(10) & """" & FnRoot & ".XML""" & " et" & Chr(10) & """" & FnRoot & ".HTML""" & Chr(10) & Chr(10) & "qui se trouvent tous les deux à """ & DirDest & """"
Open_IE DirDest, FN 'for uploading of XML- and HTML-file
' Move files to appropriate directories
If Application.UserName = "Erik" Then
Kill DirDest & "XML\" & FnRoot & ".XML"
Name DirDest & FnRoot & ".XML" As DirDest & "XML\" & FnRoot & ".XML"
Kill DirDest & "Docs\" & FnRoot & ".HTML"
Name DirDest & FnRoot & ".HTML" As DirDest & "Docs\" & FnRoot & ".HTML"
End If
' Application.Quit
End Sub
Sub Make_XML(Dir As String, FN As String)
'
' Make XML Macro
' Macro enregistrée le 04/04/2010 par Erik
'
ExportToXML Dir & FN, "Concert" '=name of top level node in XML-file
'
End Sub
Public Function ExportToXML(FullPath As String, RowName _
As String) As Boolean
On Error GoTo ErrorHandler
Dim r As Integer, colIndex As Integer, rwIndex As Integer, iFileNum As Integer
Dim c As Variant
Dim sName As String ', asCols() As String
Dim oWorkSheet As Worksheet
Dim lastCol As Long, lastRow As Long
Dim colList(7) As Integer
colList(0) = 6 ' 6 = ville
colList(1) = 7 ' 7 = lieu
colList(2) = 8 ' 8 = prog
colList(3) = 9 ' 9 = mus
colList(4) = 12 '12 = DateTimeText
colList(5) = 13 '13 = DateText
colList(6) = 14 '14 = HeureText
colList(7) = 15 '15 = DateTimeTextPeremption
Set oWorkSheet = ThisWorkbook.Worksheets(1)
sName = oWorkSheet.Name
Range("A1").Select 'Select top left corner
Selection.End(xlDown).Select 'Search bottom row
lastRow = ActiveCell.Row ':MsgBox "Bottom row = " & lastRow 'Remember bottom row
Range("A1").Select
Selection.End(xlToRight).Select 'Search most right column
lastCol = ActiveCell.Column ':MsgBox "Most right column = " & lastCol
iFileNum = FreeFile
Open FullPath For Output As #iFileNum
Print #iFileNum, "<?xml version=""1.0"" encoding=""ISO-8859-1""?>"
Print #iFileNum, "<" & sName & " Date=""" & Format(Now, "dd/mm/yyyy hh:mm") & """>"
For r = 2 To lastRow
Print #iFileNum, "<" & RowName & ">"
For Each c In colList
Cells(r, c).Select
If c < 12 Then 'protège les colonnes calculées par des formules formatées
If Trim(Cells(r, c).Value) = "" Then
Cells(r, c).Value = " "
Else
Cells(r, c).Value = Trim(Cells(r, c).Value)
End If
End If
Select Case c
Case 13: Print #iFileNum, " <" & Cells(1, c).Value & ">" & Format(Cells(r, c).Value, "dd/mm/yy") & "</" & Cells(1, c).Value & ">" 'en format de date normalisé
Case 14: Print #iFileNum, " <" & Cells(1, c).Value & ">" & Format(Cells(r, c).Value, "hh:mm") & "</" & Cells(1, c).Value & ">" 'en format de temps normalisé Case Else: Print #iFileNum, " <" & asCols(c - 1) & ">" & Cells(r, c).Value & "</" & asCols(c - 1) & ">" 'en format texte inchangé
Case Else: Print #iFileNum, " <" & Cells(1, c).Value & ">" & Cells(r, c).Value & "</" & Cells(1, c).Value & ">"
End Select
Next c
Print #iFileNum, "</" & RowName & ">"
Next r
Print #iFileNum, "</" & sName & ">"
ExportToXML = True
ErrorHandler:
If iFileNum > 0 Then Close #iFileNum
Exit Function
End Function
Sub Make_HTML(Dir As String, FN As String)
'
' Make HTML Macro
'
ExportToHTML Dir & FN
'
End Sub
Public Function ExportToHTML(FullPath As String) As Boolean
'PURPOSE: EXPORTS AN EXCEL SPREADSHEET TO HTML
'PARAMETERS: FullPath: Full Path of File to Export Sheet
'RETURNS: True if Successful, false otherwise
On Error GoTo ErrorHandler
Dim r As Integer, rr As Integer, lastRow As Integer, iFileNum As Integer, DateTimeTextCol As Integer
Dim toDay As String, firstConcert As String
Range("A1").Select 'Select top left corner
Selection.End(xlDown).Select 'Search bottom row
lastRow = ActiveCell.Row ':MsgBox "Bottomrow = " & lastRow 'Remember bottom row
DateTimeTextCol = 12
toDay = Format(Now, "yyyymmdd") ':MsgBox "toDay = " & toDay
'Seek first future concert
rr = 2
Do While Cells(rr, DateTimeTextCol).Value < toDay
Cells(rr, DateTimeTextCol).Select 'Select top left corner
rr = rr + 1
Loop
firstConcert = Cells(rr, DateTimeTextCol).Value ':MsgBox "firstConcert = " & firstConcert
iFileNum = FreeFile
Open FullPath For Output As #iFileNum
Print #iFileNum, "<!DOCTYPE html PUBLIC ""-
Print #iFileNum, "<html xmlns=""http://www.w3.org/1999/xhtml"">"
Print #iFileNum, "<head>"
Print #iFileNum, "<meta http-equiv=""Content-Type"" content=""text/html; charset=iso-8859-1"" />"
Print #iFileNum, "<title>Ulrike Van Cotthem: Prochains concerts prévus en date du " & Format(Now, "dd/mm/yyyy") & "</title>"
Print #iFileNum, "</head>"
Print #iFileNum, "<body>"
Print #iFileNum, "<table width=""100%"" border=""1"">"
Print #iFileNum, "<thead>"
Print #iFileNum, "<p style=""text-align:center;font-size:large;font-weight:bold"">Concerts chantés par Ulrike Van Cotthem entre " & Format(Cells(rr, DateTimeTextCol + 1).Value, "dd/mm/yyyy") & " et " & Format(Cells(lastRow, DateTimeTextCol + 1).Value, "dd/mm/yyyy") & "</p>"
Print #iFileNum, "</thead>"
Print #iFileNum, "<tr>"
Print #iFileNum, "<th scope=""col"">Date</th>"
Print #iFileNum, "<th scope=""col"">Heure</th>"
Print #iFileNum, "<th scope=""col"">Ville</th>"
Print #iFileNum, "<th scope=""col"">Lieu</th>"
Print #iFileNum, "<th scope=""col"">Programme</th>"
Print #iFileNum, "<th scope=""col"">Musiciens</th>"
Print #iFileNum, "</tr>"
For r = rr To lastRow
Cells(r, 13).Select 'visual tracer
Print #iFileNum, "<tr>"
Print #iFileNum, "<td>" & Cells(r, 13) & "</td>" 'date
Print #iFileNum, "<td>" & Format(Cells(r, 14), "hh:mm") & "</td>" 'heure
Print #iFileNum, "<td>" & Cells(r, 6) & "</td>" 'ville
Print #iFileNum, "<td>" & Cells(r, 7) & "</td>" 'lieu
Print #iFileNum, "<td>" & Cells(r, 8) & "</td>" 'programme
Print #iFileNum, "<td>" & Cells(r, 9) & "</td>" 'musiciens
Print #iFileNum, "</tr>"
Next r
Print #iFileNum, "</table>"
Print #iFileNum, "</body>"
Print #iFileNum, "</html>"
ExportToHTML = True
ErrorHandler:
If iFileNum > 0 Then Close #iFileNum
Exit Function
End Function
Sub Open_IE(Dir As String, FN As String)
'
' Open_IE Macro
'
Dim objFSO As Object
Dim IE, inp As Object
Set IE = CreateObject("InternetExplorer.application")
IE.Navigate "http://www.clermont-herault-concerts.fr/Ulrike_van_Cotthem_File_Upload_1.php"
IE.Visible = True
Do
DoEvents
Loop Until IE.ReadyState = 4
Set IE = Nothing
End Sub
|
|
|
|
|
I am attempting to digest someone elses xml - which is why I can't just reformat it as I'd like. I think that applying templates (possibly nested) is the way to go, but I'm buggered if I can see how to do it properly - the w3schools site covers the basics, but not what I'm after. Can anyone a) solve my problem or b) point me to somewhere I can find a more in-depth explanation?
I'd even settle for c) "XSLT does not work that way!"
Source XML:
<Beds>
<Single>
<Base>1</Base>
<BaseCode>BER</BaseCode>
<Mattress>2</Mattress>
<MattressCode>BER</MattressCode>
<Headboard>3</Headboard>
<HeadboardCode>BER</HeadboardCode>
</Single>
<Double>
<Base>0</Base>
<BaseCode></BaseCode>
<Mattress>1</Mattress>
<MattressCode>BER</MattressCode>
<Headboard>2</Headboard>
<HeadboardCode>TBD</HeadboardCode>
</Double>
<King>
<Base></Base>
<BaseCode></BaseCode>
<Mattress></Mattress>
<MattressCode></MattressCode>
<Headboard></Headboard>
<HeadboardCode></HeadboardCode>
</King>
<Sofa>
<Foam>5</Foam>
<FoamCode>BER</FoamCode>
<Metal></Metal>
<MetalCode></MetalCode>
</Sofa>
</Beds>
Desired Output XML:
<Row>
<Description>SingleBase</Description>
<Value>BER</Value>
<Quantity>1</Quantity>
</Row>
<Row>
<Description>SingleMattress</Description>
<Value>BER</Value>
<Quantity>2</Quantity>
</Row>
<Row>
<Description>SingleHeadboard</Description>
<Value>BER</Value>
<Quantity>3</Quantity>
</Row>
<Row>
<Description>DoubleMattress</Description>
<Value>BER</Value>
<Quantity>1</Quantity>
</Row>
<Row>
<Description>DoubleHeadboard</Description>
<Value>BER</Value>
<Quantity>2</Quantity>
</Row>
<Row>
<Description>SofaFoam</Description>
<Value>BER</Value>
<Quantity>5</Quantity>
</Row>
I thought I'd start with:
<xsl:for-each select="Beds">
<Row>
<xsl:apply-templates></xsl:apply-templates>
</Row>
</xsl:for-each>
but now I'm stuck as to how to access the nodename of the current node... Or whether to wrap in a choose (if that's even possible?)...
modified on Thursday, July 1, 2010 11:41 AM
|
|
|
|
|
OK, I have:
<xsl:for-each select="Beds/*/*">
<xsl:choose>
<xsl:when test="contains(name(.),'Code')">
</xsl:when>
<xsl:otherwise>
<Row>
<Category>BedDetails</Category>
<RoomName>
<xsl:value-of select="../../../RoomName"/>
</RoomName>
<Length/>
<Width/>
<Height/>
<Description>
<xsl:value-of select="name(..)"/>
<xsl:value-of select="name(.)"/>
</Description>
<Value>
<xsl:for-each select="../*">
<xsl:if test="contains(name(.),'Code')">
<xsl:value-of select="name(.)"/>
</xsl:if>
</xsl:for-each>
</Value>
<NoOfDays>0</NoOfDays>
<Quantity>
<xsl:value-of select="."/>
</Quantity>
</Row>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
Can anyone point me toward the proper XPath expression to say "sibling that begins with the name of the current element [and ends with 'Code']"? I'd like to sidestep the if, if that's possible...
Thanks,
Al
|
|
|
|
|
Neophyte30 wrote: Can anyone point me toward the proper XPath expression to say "sibling that begins with the name of the current element [and ends with 'Code']"? I'd like to sidestep the if, if that's possible...
I'd try something like:
..
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
use the 'name()' function to access a node name
The following XSLT should do what you want...
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="/">
<table>
<!-- Iterate through all bed types and items -->
<xsl:apply-templates select="Beds/*/*"/>
</table>
</xsl:template>
<!-- Just process the odd items (1st, 3rd, 5th etc) for each bed type -->
<xsl:template match="Beds/*/*[(position() mod 2) = 1]">
<xsl:if test="text() and following-sibling::*[1]/text()">
<Row>
<!-- Description is the parent name + this node's name -->
<Description><xsl:value-of select="concat(name(parent::node()), name())"/></Description>
<!-- Value is just the next sibling node's text -->
<Value><xsl:value-of select="following-sibling::*[1]/text()"/></Value>
<!-- Quantity is this node's text -->
<Quantity><xsl:value-of select="text()"/></Quantity>
</Row>
</xsl:if>
</xsl:template>
<!-- This template just sucks up the even items -->
<xsl:template match="*"/>
</xsl:stylesheet>
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
Thanks for this - I had found the "following-sibling" axis on a tutorial page somewhere which led me to:
<xsl:for-each select="Beds/*/*">
<xsl:choose>
<xsl:when test="not(contains(name(.),'Code')) and .>0">
<Row>
<Description>
<xsl:value-of select="name(..)"/>
<xsl:value-of select="name(.)"/>
</Description>
<Value>
<xsl:value-of select="following-sibling::*[contains(name(),name(.))]"/>
</Value>
<Quantity>
<xsl:value-of select="."/>
</Quantity>
</Row>
</xsl:when>
</xsl:choose>
</xsl:for-each>
Your solution demonstrates to me that I have hardly scratched the surface of XPath, and that there are many ways of achieving the same result!
Is there a performance (or other) benefit to using templates apart from the feeling of doing things properly as opposed to my schonky approach?
Can you recommend any sites or good books to get a deeper insight into XPath/XSLT?
Thanks again for your time,
Al
Edit---
My use of for-each amply demonstrates the adage that when all you have is a hammer...
|
|
|
|
|
Hi Al…thought I'd replied to this, but I guess I killed my browser without pressing Post…doh!
1. apply-templates will very likely have better performance than for-each - there's more scope for the XSLT processor to do optimisations, as apply-templates is a more abstract operation.
2. I've used Michael Kay's XSLT and XPath books, but I think Jeni Tennison's Beginning XSLT would be appropriate for what you want...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
Hey,
I have an Xml schema that I would like upload to my FTP server and have Visual Studio provide intellisense for it. Now, what I've done is that I've created the schema, uploaded to my server (http://www.vestras.net/moonlite/schemas/ximl), and then write the following in the file I'd like intellisense in:
<ximl:Markup xmlns:ximl='http://www.vestras.net/moonlite/schemas/ximl/'>
</ximl:Markup>
However, Visual Studio doesn't provide intellisense. Here's my schema code:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Ximl"
targetNamespace="http://vestras.net/moonlite/schemas/ximl"
elementFormDefault="qualified"
xmlns="http://vestras.net/moonlite/schemas/ximl"
xmlns:mstns="http://vestras.net/moonlite/schemas/ximl"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://vestras.net/moonlite/schemas/ximl http://vestras.net/moonlite/schemas/ximl/ximl.xsd">
<xs:element name="BarItem" id="BarItem">
<xs:annotation>
<xs:documentation>
Defines a bar button.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="guid" type="xs:string" use="required" />
<xs:attribute name="text" type="xs:string" use="required" />
<xs:attribute name="image" type="xs:string" use="optional" />
<xs:attribute name="commandClass" type="xs:string" use="optional" />
</xs:complexType>
</xs:element>
<xs:complexType name="Markup">
<xs:sequence>
<xs:element name="Include">
<xs:annotation>
<xs:documentation>
Includes the Ximl file at the given path.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="path" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="String">
<xs:annotation>
<xs:documentation>
Provides a string resource for later use. The resource attribute must contain a unique ID.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute name="resource" type="xs:string" use="required" />
<xs:attribute name="value" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
<xs:element name="Package">
<xs:annotation>
<xs:documentation>
Defines a package that can contain Interface elements. Must have a unique GUID.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element name="Bar">
<xs:annotation>
<xs:documentation>
Defines a bar. A bar can be a toolbar, a menu or a statusbar.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="BarItem" />
</xs:sequence>
<xs:attribute name="guid" type="xs:string" use="required" />
<xs:attribute name="type" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Menu" />
<xs:enumeration value="Bar" />
<xs:enumeration value="StatusBar" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="Menu">
<xs:annotation>
<xs:documentation>
Defines a context menu that can be shown on demand.
</xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:sequence>
<xs:element ref="BarItem" />
</xs:sequence>
<xs:attribute name="guid" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="guid" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
Any help will be really appreciated.
Thanks,
Theo
|
|
|
|
|
To get Intillisense for Visual Studio the schema file must be placed here
[VS Folder]\Common7\Packages\schemas\xml
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Okay, so I did that and now the schema shows up on the schema list, however when it is included, it doesn't give me any options, it just says "The 'http://vestras.net/moonlite/schemas/ximl:Markup' element is not declared." What does this mean? The Markup element is declared.
|
|
|
|
|
need a little help with this one please.
i have an xml document that contains nodes with cdata sections and am transforming it with xsl. i can get the cdata section to render properly by using <xsl:value-of select="content" disable-output-escaping="yes"/> in my <xsl:template> but if i try to pass the results of that template to another template my cdata section becomes escaped. i tried converting the cdata section to an escaped attribute in my xml but get the same problem.
even an answer of "sorry, not possible." is greatful as i've been trying everything i can think of to get this to work and have come up with nothing.
i can restructure my xml if need be, only i cannot convert the cdata content to valid xml (it needs to be escaped).
sample code:
<xsl:template match="/">
<xsl:variable name="myStructuredContent"><xsl:call-template name="GetStructuredContent"/></xsl:variable>
<xsl:call-template name="Container_RoundedCorners">
<xsl:with-param name="content" select="$myStructuredContent">
</xsl:call-template>
</xsl:template>
<xsl:template name="GetStructuredContent">
<h2><xsl:value-of select="title"/></h2>
<div><xsl:value-of select="content" disable-output-escaping="yes"/></div>
<div><a href="{morelinkhref}"><xsl:value-of select="morelinktext"/></a></div>
</xsl:template>
<xsl:template name="Container_RoundedCorners">
<xsl:param name="content"/>
<div class="RoundedCornerTopLeft"><div class="RoundedCornerTopRight"><xsl:copy-of select="$content"/></div></div>
</xsl:template>
thanks a bazillion in advance.
|
|
|
|
|