|
Just make a google spreadsheet, that's all.
|
|
|
|
|
I've got an XML file full of user details including 'FirstName', 'Surname' and 'StreetAddress'.
Currently my XSL file has a template (SurnameAlphabetGrouping) that groups users by the first character of the Surname element's value. I've only provided the process for 'A' to save space. All 26 letters are processed.
<xsl:template name="SurnameAlphabetGrouping">
<xsl:variable name="AMatch" select="/Users/User[starts-with(Surname, 'A')]"/>
<xsl:variable name="ACount" select="count($AMatch)"/>
<xsl:if test="$ACount > 0">
<h2>
<a href="javascript:void(0)" class="dsphead" onclick="dsp(this)">
+ A (<xsl:value-of select="$ACount"/>)
</a>
</h2>
<div class="dspcont">
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<xsl:call-template name="HeadingRow"/>
</tr>
<xsl:for-each select="/Users/User[starts-with(Surname, 'A')]">
<xsl:sort select="Surname"/>
<xsl:call-template name="UserRow"/>
</xsl:for-each>
</table>
</div>
</xsl:if>
</xsl:template>
That's all well and good. But now that I've got it working that way, I really want to make it smarter (i.e. cut down the code), so I'm trying to build a template that can take the required character as a parameter.
I've got a variable (Letters) that carries tokens for the 26 letters of the alphabet:
<xsl:variable name="Letters">
<xsl:call-template name="tokenise">
<xsl:with-param name="string" select ="'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'"/>
<xsl:with-param name="delimeters" select="' '"/>
</xsl:call-template>
</xsl:variable>
I'm then attempting to process each token, passing it to the template as a parameter:
<xsl:for-each select="msxsl:node-set($Letters)/token">
<xsl:variable name="currToken" select ="./node()[1]"/>
<xsl:call-template name="ListSurnameStartsWith">
<xsl:with-param name="character" select="$currToken"/>
</xsl:call-template>
</xsl:for-each>
This is the template as it stands at the moment:
<xsl:template name="ListSurnameStartsWith">
<xsl:param name="character" select="''"/>
<xsl:variable name="charMatch" select="/Users/User[starts-with(Surname, $character)]"/>
<xsl:variable name="charCount" select="count($charMatch)"/>
<xsl:if test="$charCount > 0">
<h2>
<a href="javascript:void(0)" class="dsphead" onclick="dsp(this)">
+ <xsl:value-of select="$character"/> (<xsl:value-of select="$charCount"/>)
</a>
</h2>
<div class="dspcont">
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<xsl:call-template name="HeadingRow"/>
</tr>
<xsl:for-each select="/Users/User[starts-with(Surname, $character)]">
<xsl:sort select="Surname"/>
<xsl:call-template name="UserRow"/>
</xsl:for-each>
</table>
</div>
</xsl:if>
</xsl:template>
'currToken' is getting the value I want. It's landing in the 'ListSurnameStartsWith' template just fine, but 'charMatch' just comes back blank all the time, meaning I can't get a meaningful count to test whether the output needs to be generated. The later '
|
|
|
|
|
Are you absolutely certain that the character parameter is getting the correct string value?
I've just tried the following simplified example, and it works as expected:
="1.0"
<bookstore>
<book>
<title>The Weather Pattern</title>
<author>Weather Man</author>
<price>100.00</price>
</book>
<book>
<title>Weaving Patterns</title>
<author>Weaver</author>
<price>150.00</price>
</book>
<book>
<title>Speech Pattern</title>
<author>Speaker</author>
<price>15.00</price>
</book>
<book>
<title>Writing Style</title>
<author>Writer</author>
<price>1500.00</price>
</book>
</bookstore>
="1.0"
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<root>
<xsl:apply-templates select="/bookstore">
<xsl:with-param name="character" select="'W'" />
</xsl:apply-templates>
</root>
</xsl:template>
<xsl:template match="bookstore">
<xsl:param name="character" select="''" />
<xsl:variable name="charMatch" select="book[starts-with(title, $character)]"/>
<xsl:variable name="charCount" select="count($charMatch)"/>
<result>
<char><xsl:value-of select="$character" /></char>
<count><xsl:value-of select="$charCount" /></count>
<books>
<xsl:for-each select="$charMatch">
<xsl:copy-of select="." />
</xsl:for-each>
</books>
</result>
</xsl:template>
</xsl:stylesheet>
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard,
Thanks for your reply.
Yes, if I pass 'A' to the template, I get the correct answer. So that's a good thing.
Now, given a tokenised string stored in a variable (Letters):
<xsl:variable name="Letters">
<xsl:call-template name="tokenise">
<xsl:with-param name="string" select ="'A B C D E F G H I J K L M N O P Q R S T U V W X Y Z'"/>
<xsl:with-param name="delimeters" select="' '"/>
</xsl:call-template>
</xsl:variable>
And trying to process each token through the template:
<xsl:for-each select="msxsl:node-set($Letters)/token">
<xsl:variable name="currToken">
<xsl:value-of select="./node()[1]"/>
</xsl:variable>
<xsl:call-template name="ListSurnameStartsWith">
<xsl:with-param name="character" select="$currToken"/>
</xsl:call-template>
</xsl:for-each>
What should I be using inside the 'select' attribute to ensure that i get 'A' and not some other value.
Some options I've tried, debugging in Visual Studio 2013, are:
<xsl:variable name="currToken">
<xsl:value-of select="."/>
</xsl:variable>
This gives me:
$currToken {Dimension:[1]}
[1] /
node()[1] A
'select="./node()"' gives me the same answer.
'select="./node()[1]"' gives me the same answer.
I haven't had any help from Google, as I can't seem to ask the right question, or nobody's doing this.
What do I need to put into the select to actually get the character A.
|
|
|
|
|
Have you tried:
./text()[1]
If that doesn't work, can you post your "tokenise" template?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard,
Sorry I haven't replied earlier. I went on leave the day you responded and have been... occupied since.
I tried your suggestion, without success, although it has given me something to pursue.
As requested, the tokenisation templates I gleaned from other forum sources a fair while ago are below. It worked well for what I was doing then, but it may not be the best for what I'm attempting now.
Any advice would be appreciated.
<xsl:template name="tokenise">
<xsl:param name="string" select="''" />
<xsl:param name="delimiters" select="' '" />
<xsl:choose>
<xsl:when test="not($string)" />
<xsl:when test="not($delimiters)">
<xsl:call-template name="_tokenise-characters">
<xsl:with-param name="string" select="$string" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="_tokenise-delimiters">
<xsl:with-param name="string" select="$string" />
<xsl:with-param name="delimiters" select="$delimiters" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="_tokenise-characters">
<xsl:param name="string" />
<xsl:if test="$string">
<token>
<xsl:value-of select="substring($string, 1, 1)" />
</token>
<xsl:call-template name="_tokenise-characters">
<xsl:with-param name="string" select="substring($string, 2)" />
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="_tokenise-delimiters">
<xsl:param name="string" />
<xsl:param name="delimiters" />
<xsl:param name="last-delimit"/>
<xsl:variable name="delimiter" select="substring($delimiters, 1, 1)" />
<xsl:choose>
<xsl:when test="not($delimiter)">
<token>
<xsl:value-of select="$string"/>
</token>
</xsl:when>
<xsl:when test="contains($string, $delimiter)">
<xsl:if test="not(starts-with($string, $delimiter))">
<xsl:call-template name="_tokenise-delimiters">
<xsl:with-param name="string"
select="substring-before($string, $delimiter)" />
<xsl:with-param name="delimiters"
select="substring($delimiters, 2)" />
</xsl:call-template>
</xsl:if>
<xsl:call-template name="_tokenise-delimiters">
<xsl:with-param name="string"
select="substring-after($string, $delimiter)" />
<xsl:with-param name="delimiters" select="$delimiters" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="_tokenise-delimiters">
<xsl:with-param name="string"
select="$string" />
<xsl:with-param name="delimiters"
select="substring($delimiters, 2)" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
|
|
|
|
|
OK, I think I've found the problem.
Within the <xsl:for-each select="msxsl:node-set($Letters)/token"> , the default context is the node-set returned from your "tokenise" template. When you try to resolve /Users , it's looking in that node set, rather than the source document.
You need to capture the nodes from the source document that you want to process, and pass those to the template:
<xsl:variable name="users" select="/Users" />
<xsl:for-each select="msxsl:node-set($Letters)/token">
<xsl:variable name="currToken" select ="./node()[1]"/>
<xsl:call-template name="ListSurnameStartsWith">
<xsl:with-param name="users" select="$users"/>
<xsl:with-param name="character" select="$currToken"/>
</xsl:call-template>
</xsl:for-each>
Update the template to:
<xsl:template name="ListSurnameStartsWith">
<xsl:param name="users" />
<xsl:param name="character" select="''"/>
<xsl:variable name="charMatch" select="$users/User[starts-with(Surname, $character)]"/>
<xsl:variable name="charCount" select="count($charMatch)"/>
<xsl:if test="$charCount > 0">
<h2>
<a href="javascript:void(0)" class="dsphead" onclick="dsp(this)">
<span class="dspchar">+</span> <xsl:value-of select="$character"/> (<xsl:value-of select="$charCount"/>)
</a>
</h2>
<div class="dspcont">
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<xsl:call-template name="HeadingRow"/>
</tr>
<xsl:for-each select="$charMatch">
<xsl:sort select="Surname"/>
<xsl:call-template name="UserRow"/>
</xsl:for-each>
</table>
</div>
</xsl:if>
</xsl:template>
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard,
Thank you. That extra piece of understanding did the trick.
Regards
Brendan
|
|
|
|
|
Hi there,
I have a one big prob.
I want to generate xml file with a specific format Like this syntax!:
<declarationrelevededuction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<identifiantfiscal>1088081
<annee>2016
<periode>8
<regime>1
<relevedeductions>
<rd>
<ord>1
<num>FF160400146
<des>PRESTATION
<mht>2400.00
<tva>480.00
<ttc>2880.00
<reff>
<if>52803595
<nom>LEADER SOFT
<ice>001540114000046
<tx>20.00
<mp>
<id>2
<dpai>2016-08-01
<dfac>2016-01-30
<rd>
<ord>2
<num>FF160400147
<des>PRESTATION
<mht>1500.00
<tva>300.00
<ttc>1800.00
<reff>
<if>52803595
<nom>LEADER SOFT
<ice>001540114000046
<tx>20.00
<mp>
So, I've created form with button to generate the xml files and I created this code for That:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim xmlsetting As New XmlWriterSettings
'xmlsetting.ConformanceLevel = ConformanceLevel.Document
'xmlsetting.OmitXmlDeclaration = True
Dim writxml As XmlWriter = XmlWriter.Create("mytest.xml", xmlsetting)
Try
With writxml
.WriteStartDocument()
.WriteStartElement("DeclarationReleveDeduction")
.WriteStartElement("identifiantFiscal")
.WriteString("111111")
.WriteEndElement()
.WriteStartElement("annee")
.WriteString("2016")
.WriteEndElement()
.WriteStartElement("periode")
.WriteString("8")
.WriteEndElement()
.WriteStartElement("regime")
.WriteString("1")
.WriteEndElement()
.WriteStartElement("Relvededution")
For i As Integer = 1 To 10
.WriteStartElement("Id")
.WriteString(i)
.WriteStartElement("Nom")
.WriteString("Nom " & i)
.WriteEndElement()
.WriteStartElement("prenom")
.WriteString("Prenom " & i)
.WriteEndElement()
.WriteStartElement("Adresse")
.WriteString("Adresse " & i)
.WriteEndElement()
.WriteEndElement()
Next
.WriteEndElement()
.WriteEndElement()
.WriteEndDocument()
.Close()
End With
MsgBox("fichier a été généré avec succès", vbInformation)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
when I generated the xml file I have got like this format:
<declarationrelevededuction><identifiantfiscal>111111<annee>2016<periode>8<regime>1<relvededution><id>1<nom>Nom 1<prenom>Prenom 1<adresse>Adresse 1<id>2<nom>Nom 2<prenom>Prenom 2<adresse>Adresse 2<id>3<nom>Nom 3<prenom>Prenom 3<adresse>Adresse 3<id>4<nom>Nom 4<prenom>Prenom 4<adresse>Adresse 4<id>5<nom>Nom 5<prenom>Prenom 5<adresse>Adresse 5<id>6<nom>Nom 6<prenom>Prenom 6<adresse>Adresse 6<id>7<nom>Nom 7<prenom>Prenom 7<adresse>Adresse 7<id>8<nom>Nom 8<prenom>Prenom 8<adresse>Adresse 8<id>9<nom>Nom 9<prenom>Prenom 9<adresse>Adresse 9<id>10<nom>Nom 10<prenom>Prenom 10<adresse>Adresse 10
Please help me I need to do that in this days of current month Cry | Confused |
|
|
|
|
|
|
<xsl:attribute name="name">Insured1BirthDate</xsl:attribute>
<xsl:if test="function-available('ExFunctions:FormatDate')">
<xsl:value-of select="ExFunctions:FormatDate(X-pathh,'mm/dd/yyyy')"/>
</xsl:if>
|
|
|
|
|
You forgot to ask a question.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Help me read value in note <Code>, <Message>, <Time>
string result = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>
<string xmlns=\"http://tempuri.org/\">
<AAA>
<Code>5</Code>
<Message>Send MT Error!.</Message>
<Time></Time>
</AAA>
</string>"
XmlReader xReader = XmlReader.Create(new StringReader(result));
while (xReader.Read())
{
??????????????
}
Thanks so much!
^_^_^
modified 26-Aug-17 0:24am.
|
|
|
|
|
|
|
I am getting this message when I try to validate my xml document: 13:2 The markup in the document following the root element must be well-formed. Every time when I try to fix line 13, I get the same error message.
="1.0"
<registration_form>
<name>Digestive and Endoscopy Medical Office MD</name>
<register>patient information</register>
<patient>Arijit Singh</patient>
<status>Single</status>
<birthdate>10/20/1987</birthdate>
<age>27</age>
<address>6216 GreatWater Dr, Windermer, FL 34786</address>
<home>(407)-987-2525</home>
<cell>(407)-288-9331</cell>
</registration_form>
<patient employment>
<employer <information>Orlando Home Team</employer>
<occupation>Real Estate Agent</occupation>
<address>1300 e Michigan St, Orlando, FL 32812</address>
<employer>(407)-885-3539</employer>
<patient employment>
<Insurance_Information>
<subscriber>Arijit Singh</subscriber>
<subscriber's S.S.>789-53-3407</subscriber's S.S.>
<group>DC2630</group>
<co-payment>$50</co-payment>
</Insurance_Information>
<In Case of Emergency>
<name>Zina Kaur</name>
<relationship>fiancee</relationship>
<authorization>Arijit Singh</authorization>
</In Case of Emergency>
|
|
|
|
|
See wikipedia: XML - Wikipedia, the free encyclopedia[^]
Quote: Tag names cannot contain any of the characters !"#$%&'()*+,/;<=>?@[\]^`{|}~, nor a space character, and cannot begin with "-", ".", or a numeric digit.
<patient employment> Contains a space.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I tried to write the code just like that <patient employment=""> and this <patient_employment> and <patientemployment> and I still get an error message.
|
|
|
|
|
I tried that but it did not work and I tried <patient_employment> and I tried <patientemployment> and I still got an error.
|
|
|
|
|
And did you take a good look at the line below that as well?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Yes I did. But I still did not find any solutions to the error.
|
|
|
|
|
And what did you see?
I'll give you a clue:
<employer <information>Orlando Home Team</employer>
What is that? Does it look well formed to you?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
no, that does not look correct. This is how I wrote the code
<employerinformation>Orlando Home Team></employerinfomation>
|
|
|
|
|
And that doesn't look right either...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
To this point I do not know what I am doing wrong. could you just please point out what I am doing wrong and how to fix it. I have been working on this for three days and I still could not figure it out.
|
|
|
|