Как посчитать количество строк в xml
Перейти к содержимому

Как посчитать количество строк в xml

  • автор:

Как узнать количество строк кода в проекте?

Проект, состоящий из множества файлов (например *.java и *.xml ).

Задача:

Подсчитать сколько строк кода во всех этих файлах. Исключая комменты и пустые строки.

Вопрос:

Пилить свой велосипед или я не первый кто этим интересуется?

ЮрийСПб's user avatar

Решение задачи, в общих чертах, должно выглядеть так:

  1. Собираем список всех файлов в проекте, пробежавшись по всем его папкам.
  2. Считываем файл и считаем в нём кол-во строк
  3. Регулярками (например) выкидываем из общего числа строк файла пустые строки и закомментированные строки (в зависимости от типа файла и ЯП, определяем как именно выглядит коммент)

И да, есть готовые решения. Например, вот на гитхабе: Count Lines of Code

Вкратце алгоритм такой (для масдая):

  1. Скачиваем *.exe .
  2. Запускаем его из командной строки
  3. Указываем папку с исходниками.
  4. Получаем результат подобного вида:

введите сюда описание изображения

P.S.

У Count Lines of Code есть множество ограничений. Например «/*» тут n строк кода «*/» будут восприняты как n строк комментов. Также подсчёт идёт не логических строк кода, а непустых строк, содержащих то, что программа определяет как код, а не комменты.

Обратите внимание на приведённый в README проекта список альтернативных решений.

Подсчитать количество строк в XSLT

При преобразовании этого XML мне нужно подсчитать количество разрывов строк в этом узле XML.

Как и в приведенном выше примере, есть 14 разрывов строк.

Я попытался определить количество вхождений » 
 , а также 
 «, но даже если в приведенном выше XML нет изменений, количество вхождений будет меняться каждый раз, когда этот XML подвергается сериализации/десериализации.

У кого-нибудь есть идеи, как я могу получить количество строк из значения узла XML в XSLT?

задан 28 июн ’12, 11:06

2 ответы

Используйте:

Хотя при использовании приведенного выше однострочника XPath вам вообще не нужен XSLT, для полноты вот он:

Когда это преобразование применяется к предоставленному XML-документу:

будет получен желаемый, правильный результат:

Обратите внимание:

Это решение только подсчитывает количество символов NL. Почему я проигнорировал CR? Просто потому, что согласно Спецификация W3C XML, любой совместимый синтаксический анализатор XML должен выполнять следующие действия:

все символы #xD, буквально присутствующие в XML-документе, либо удаляются, либо заменяются символами #xA до того, как будет выполнена какая-либо другая обработка.

Как посчитать количество строк в xml

Профиль
Группа: Участник
Сообщений: 3
Регистрация: 12.5.2009

Репутация: нет
Всего: нет

Код
<?xml version="1.0"?>
<!DOCTYPE PLAY SYSTEM "play.dtd">

<FM>
<P>ASCII text placed in the public domain by Moby Lexical Tools, 1992.</P>
<P>SGML markup by Jon Bosak, 1992-1994.</P>
<P>XML version by Jon Bosak, 1996-1999.</P>
<P>The XML markup in this version is Copyright © 1999 Jon Bosak.
This work may freely be distributed on condition that it not be
modified or altered in any way.</P>
</FM>

<PERSONA>THESEUS, Duke of Athens.</PERSONA>
<PERSONA>EGEUS, father to Hermia.</PERSONA>

<PERSONA>PHILOSTRATE, master of the revels to Theseus.</PERSONA>
<PERSONA>QUINCE, a carpenter.</PERSONA>
<PERSONA>SNUG, a joiner.</PERSONA>
<PERSONA>BOTTOM, a weaver.</PERSONA>
<PERSONA>FLUTE, a bellows-mender.</PERSONA>
<PERSONA>SNOUT, a tinker.</PERSONA>
<PERSONA>STARVELING, a tailor.</PERSONA>
<PERSONA>HIPPOLYTA, queen of the Amazons, betrothed to Theseus.</PERSONA>
<PERSONA>HERMIA, daughter to Egeus, in love with Lysander.</PERSONA>
<PERSONA>HELENA, in love with Demetrius.</PERSONA>
<PERSONA>OBERON, king of the fairies.</PERSONA>
<PERSONA>TITANIA, queen of the fairies.</PERSONA>
<PERSONA>PUCK, or Robin Goodfellow.</PERSONA>

<PERSONA>Other fairies attending their King and Queen.</PERSONA>
<PERSONA>Attendants on Theseus and Hippolyta.</PERSONA>
</PERSONAE>

<SCNDESCR>SCENE Athens, and a wood near it.</SCNDESCR>

<PLAYSUBT>A MIDSUMMER NIGHT'S DREAM</PLAYSUBT>

<SCENE><TITLE>SCENE I. Athens. The palace of THESEUS.</TITLE>
<STAGEDIR>Enter THESEUS, HIPPOLYTA, PHILOSTRATE, and
Attendants</STAGEDIR>

<SPEECH>
<SPEAKER>THESEUS</SPEAKER>
<LINE>Now, fair Hippolyta, our nuptial hour</LINE>
<LINE>Draws on apace; four happy days bring in</LINE>
<LINE>Another moon: but, O, methinks, how slow</LINE>
<LINE>This old moon wanes! she lingers my desires,</LINE>
<LINE>Like to a step-dame or a dowager</LINE>
<LINE>Long withering out a young man revenue.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>HIPPOLYTA</SPEAKER>
<LINE>Four days will quickly steep themselves in night;</LINE>
<LINE>Four nights will quickly dream away the time;</LINE>
<LINE>And then the moon, like to a silver bow</LINE>
<LINE>New-bent in heaven, shall behold the night</LINE>
<LINE>Of our solemnities.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>THESEUS</SPEAKER>
<LINE>Go, Philostrate,</LINE>
<LINE>Stir up the Athenian youth to merriments;</LINE>
<LINE>Awake the pert and nimble spirit of mirth;</LINE>
<LINE>Turn melancholy forth to funerals;</LINE>
<LINE>The pale companion is not for our pomp.</LINE>
<STAGEDIR>Exit PHILOSTRATE</STAGEDIR>
<LINE>Hippolyta, I woo'd thee with my sword,</LINE>
<LINE>And won thy love, doing thee injuries;</LINE>
<LINE>But I will wed thee in another key,</LINE>
<LINE>With pomp, with triumph and with revelling.</LINE>
</SPEECH>

<STAGEDIR>Enter EGEUS, HERMIA, LYSANDER, and DEMETRIUS</STAGEDIR>

<SPEECH>
<SPEAKER>EGEUS</SPEAKER>
<LINE>Full of vexation come I, with complaint</LINE>
<LINE>Against my child, my daughter Hermia.</LINE>
<LINE>Stand forth, Demetrius. My noble lord,</LINE>
<LINE>This man hath my consent to marry her.</LINE>
<LINE>Stand forth, Lysander: and my gracious duke,</LINE>
<LINE>This man hath bewitch'd the bosom of my child;</LINE>
<LINE>Thou, thou, Lysander, thou hast given her rhymes,</LINE>
<LINE>And interchanged love-tokens with my child:</LINE>
<LINE>Thou hast by moonlight at her window sung,</LINE>
<LINE>With feigning voice verses of feigning love,</LINE>
<LINE>And stolen the impression of her fantasy</LINE>
<LINE>With bracelets of thy hair, rings, gawds, conceits,</LINE>
<LINE>Knacks, trifles, nosegays, sweetmeats, messengers</LINE>
<LINE>Of strong prevailment in unharden'd youth:</LINE>
<LINE>With cunning hast thou filch'd my daughter's heart,</LINE>
<LINE>Turn'd her obedience, which is due to me,</LINE>
<LINE>To stubborn harshness: and, my gracious duke,</LINE>
<LINE>Be it so she; will not here before your grace</LINE>
<LINE>Consent to marry with Demetrius,</LINE>
<LINE>I beg the ancient privilege of Athens,</LINE>
<LINE>As she is mine, I may dispose of her:</LINE>
<LINE>Which shall be either to this gentleman</LINE>
<LINE>Or to her death, according to our law</LINE>
<LINE>Immediately provided in that case.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>THESEUS</SPEAKER>
<LINE>What say you, Hermia? be advised fair maid:</LINE>
<LINE>To you your father should be as a god;</LINE>
<LINE>One that composed your beauties, yea, and one</LINE>
<LINE>To whom you are but as a form in wax</LINE>
<LINE>By him imprinted and within his power</LINE>
<LINE>To leave the figure or disfigure it.</LINE>
<LINE>Demetrius is a worthy gentleman.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>THESEUS</SPEAKER>
<LINE>In himself he is;</LINE>
<LINE>But in this kind, wanting your father's voice,</LINE>
<LINE>The other must be held the worthier.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>THESEUS</SPEAKER>
<LINE>Rather your eyes must with his judgment look.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>HERMIA</SPEAKER>
<LINE>I do entreat your grace to pardon me.</LINE>
<LINE>I know not by what power I am made bold,</LINE>
<LINE>Nor how it may concern my modesty,</LINE>
<LINE>In such a presence here to plead my thoughts;</LINE>
<LINE>But I beseech your grace that I may know</LINE>
<LINE>The worst that may befall me in this case,</LINE>
<LINE>If I refuse to wed Demetrius.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>THESEUS</SPEAKER>
<LINE>Either to die the death or to abjure</LINE>
<LINE>For ever the society of men.</LINE>
<LINE>Therefore, fair Hermia, question your desires;</LINE>
<LINE>Know of your youth, examine well your blood,</LINE>
<LINE>Whether, if you yield not to your father's choice,</LINE>
<LINE>You can endure the livery of a nun,</LINE>
<LINE>For aye to be in shady cloister mew'd,</LINE>
<LINE>To live a barren sister all your life,</LINE>
<LINE>Chanting faint hymns to the cold fruitless moon.</LINE>
<LINE>Thrice-blessed they that master so their blood,</LINE>
<LINE>To undergo such maiden pilgrimage;</LINE>
<LINE>But earthlier happy is the rose distill'd,</LINE>
<LINE>Than that which withering on the virgin thorn</LINE>
<LINE>Grows, lives and dies in single blessedness.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>HERMIA</SPEAKER>
<LINE>So will I grow, so live, so die, my lord,</LINE>
<LINE>Ere I will my virgin patent up</LINE>
<LINE>Unto his lordship, whose unwished yoke</LINE>
<LINE>My soul consents not to give sovereignty.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>THESEUS</SPEAKER>
<LINE>Take time to pause; and, by the nest new moon—</LINE>
<LINE>The sealing-day betwixt my love and me,</LINE>
<LINE>For everlasting bond of fellowship—</LINE>
<LINE>Upon that day either prepare to die</LINE>
<LINE>For disobedience to your father's will,</LINE>
<LINE>Or else to wed Demetrius, as he would;</LINE>
<LINE>Or on Diana's altar to protest</LINE>
<LINE>For aye austerity and single life.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>DEMETRIUS</SPEAKER>
<LINE>Relent, sweet Hermia: and, Lysander, yield</LINE>
<LINE>Thy crazed title to my certain right.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>LYSANDER</SPEAKER>
<LINE>You have her father's love, Demetrius;</LINE>
<LINE>Let me have Hermia's: do you marry him.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>EGEUS</SPEAKER>
<LINE>Scornful Lysander! true, he hath my love,</LINE>
<LINE>And what is mine my love shall render him.</LINE>
<LINE>And she is mine, and all my right of her</LINE>
<LINE>I do estate unto Demetrius.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>LYSANDER</SPEAKER>
<LINE>I am, my lord, as well derived as he,</LINE>
<LINE>As well possess'd; my love is more than his;</LINE>
<LINE>My fortunes every way as fairly rank'd,</LINE>
<LINE>If not with vantage, as Demetrius';</LINE>
<LINE>And, which is more than all these boasts can be,</LINE>
<LINE>I am beloved of beauteous Hermia:</LINE>
<LINE>Why should not I then prosecute my right?</LINE>
<LINE>Demetrius, I'll avouch it to his head,</LINE>
<LINE>Made love to Nedar's daughter, Helena,</LINE>
<LINE>And won her soul; and she, sweet lady, dotes,</LINE>
<LINE>Devoutly dotes, dotes in idolatry,</LINE>
<LINE>Upon this spotted and inconstant man.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>THESEUS</SPEAKER>
<LINE>I must confess that I have heard so much,</LINE>
<LINE>And with Demetrius thought to have spoke thereof;</LINE>
<LINE>But, being over-full of self-affairs,</LINE>
<LINE>My mind did lose it. But, Demetrius, come;</LINE>
<LINE>And come, Egeus; you shall go with me,</LINE>
<LINE>I have some private schooling for you both.</LINE>
<LINE>For you, fair Hermia, look you arm yourself</LINE>
<LINE>To fit your fancies to your father's will;</LINE>
<LINE>Or else the law of Athens yields you up—</LINE>
<LINE>Which by no means we may extenuate—</LINE>
<LINE>To death, or to a vow of single life.</LINE>
<LINE>Come, my Hippolyta: what cheer, my love?</LINE>
<LINE>Demetrius and Egeus, go along:</LINE>
<LINE>I must employ you in some business</LINE>
<LINE>Against our nuptial and confer with you</LINE>
<LINE>Of something nearly that concerns yourselves.</LINE>
</SPEECH>

<STAGEDIR>Exeunt all but LYSANDER and HERMIA</STAGEDIR>

<SPEECH>
<SPEAKER>LYSANDER</SPEAKER>
<LINE>How now, my love! why is your cheek so pale?</LINE>
<LINE>How chance the roses there do fade so fast?</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>HERMIA</SPEAKER>
<LINE>Belike for want of rain, which I could well</LINE>
<LINE>Beteem them from the tempest of my eyes.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>LYSANDER</SPEAKER>
<LINE>Ay me! for aught that I could ever read,</LINE>
<LINE>Could ever hear by tale or history,</LINE>
<LINE>The course of true love never did run smooth;</LINE>
<LINE>But, either it was different in blood,—</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>LYSANDER</SPEAKER>
<LINE>Or else it stood upon the choice of friends,—</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>LYSANDER</SPEAKER>
<LINE>Or, if there were a sympathy in choice,</LINE>
<LINE>War, death, or sickness did lay siege to it,</LINE>
<LINE>Making it momentany as a sound,</LINE>
<LINE>Swift as a shadow, short as any dream;</LINE>
<LINE>Brief as the lightning in the collied night,</LINE>
<LINE>That, in a spleen, unfolds both heaven and earth,</LINE>
<LINE>And ere a man hath power to say 'Behold!'</LINE>
<LINE>The jaws of darkness do devour it up:</LINE>
<LINE>So quick bright things come to confusion.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>HERMIA</SPEAKER>
<LINE>If then true lovers have been ever cross'd,</LINE>
<LINE>It stands as an edict in destiny:</LINE>
<LINE>Then let us teach our trial patience,</LINE>
<LINE>Because it is a customary cross,</LINE>
<LINE>As due to love as thoughts and dreams and sighs,</LINE>
<LINE>Wishes and tears, poor fancy's followers.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>LYSANDER</SPEAKER>
<LINE>A good persuasion: therefore, hear me, Hermia.</LINE>
<LINE>I have a widow aunt, a dowager</LINE>
<LINE>Of great revenue, and she hath no child:</LINE>
<LINE>From Athens is her house remote seven leagues;</LINE>
<LINE>And she respects me as her only son.</LINE>
<LINE>There, gentle Hermia, may I marry thee;</LINE>
<LINE>And to that place the sharp Athenian law</LINE>
<LINE>Cannot pursue us. If thou lovest me then,</LINE>
<LINE>Steal forth thy father's house to-morrow night;</LINE>
<LINE>And in the wood, a league without the town,</LINE>
<LINE>Where I did meet thee once with Helena,</LINE>
<LINE>To do observance to a morn of May,</LINE>
<LINE>There will I stay for thee.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>HERMIA</SPEAKER>
<LINE>My good Lysander!</LINE>
<LINE>I swear to thee, by Cupid's strongest bow,</LINE>
<LINE>By his best arrow with the golden head,</LINE>
<LINE>By the simplicity of Venus' doves,</LINE>
<LINE>By that which knitteth souls and prospers loves,</LINE>
<LINE>And by that fire which burn'd the Carthage queen,</LINE>
<LINE>When the false Troyan under sail was seen,</LINE>
<LINE>By all the vows that ever men have broke,</LINE>
<LINE>In number more than ever women spoke,</LINE>
<LINE>In that same place thou hast appointed me,</LINE>
<LINE>To-morrow truly will I meet with thee.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>HELENA</SPEAKER>
<LINE>Call you me fair? that fair again unsay.</LINE>
<LINE>Demetrius loves your fair: O happy fair!</LINE>
<LINE>Your eyes are lode-stars; and your tongue's sweet air</LINE>
<LINE>More tuneable than lark to shepherd's ear,</LINE>
<LINE>When wheat is green, when hawthorn buds appear.</LINE>
<LINE>Sickness is catching: O, were favour so,</LINE>
<LINE>Yours would I catch, fair Hermia, ere I go;</LINE>
<LINE>My ear should catch your voice, my eye your eye,</LINE>
<LINE>My tongue should catch your tongue's sweet melody.</LINE>
<LINE>Were the world mine, Demetrius being bated,</LINE>
<LINE>The rest I'd give to be to you translated.</LINE>
<LINE>O, teach me how you look, and with what art</LINE>
<LINE>You sway the motion of Demetrius' heart.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>HELENA</SPEAKER>
<LINE>O that your frowns would teach my smiles such skill!</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>HELENA</SPEAKER>
<LINE>O that my prayers could such affection move!</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>HELENA</SPEAKER>
<LINE>None, but your beauty: would that fault were mine!</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>HERMIA</SPEAKER>
<LINE>Take comfort: he no more shall see my face;</LINE>
<LINE>Lysander and myself will fly this place.</LINE>
<LINE>Before the time I did Lysander see,</LINE>
<LINE>Seem'd Athens as a paradise to me:</LINE>
<LINE>O, then, what graces in my love do dwell,</LINE>
<LINE>That he hath turn'd a heaven unto a hell!</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>LYSANDER</SPEAKER>
<LINE>Helen, to you our minds we will unfold:</LINE>
<LINE>To-morrow night, when Phoebe doth behold</LINE>
<LINE>Her silver visage in the watery glass,</LINE>
<LINE>Decking with liquid pearl the bladed grass,</LINE>
<LINE>A time that lovers' flights doth still conceal,</LINE>
<LINE>Through Athens' gates have we devised to steal.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>HERMIA</SPEAKER>
<LINE>And in the wood, where often you and I</LINE>
<LINE>Upon faint primrose-beds were wont to lie,</LINE>
<LINE>Emptying our bosoms of their counsel sweet,</LINE>
<LINE>There my Lysander and myself shall meet;</LINE>
<LINE>And thence from Athens turn away our eyes,</LINE>
<LINE>To seek new friends and stranger companies.</LINE>
<LINE>Farewell, sweet playfellow: pray thou for us;</LINE>
<LINE>And good luck grant thee thy Demetrius!</LINE>
<LINE>Keep word, Lysander: we must starve our sight</LINE>
<LINE>From lovers' food till morrow deep midnight.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>HELENA</SPEAKER>
<LINE>How happy some o'er other some can be!</LINE>
<LINE>Through Athens I am thought as fair as she.</LINE>
<LINE>But what of that? Demetrius thinks not so;</LINE>
<LINE>He will not know what all but he do know:</LINE>
<LINE>And as he errs, doting on Hermia's eyes,</LINE>
<LINE>So I, admiring of his qualities:</LINE>
<LINE>Things base and vile, folding no quantity,</LINE>
<LINE>Love can transpose to form and dignity:</LINE>
<LINE>Love looks not with the eyes, but with the mind;</LINE>
<LINE>And therefore is wing'd Cupid painted blind:</LINE>
<LINE>Nor hath Love's mind of any judgement taste;</LINE>
<LINE>Wings and no eyes figure unheedy haste:</LINE>
<LINE>And therefore is Love said to be a child,</LINE>
<LINE>Because in choice he is so oft beguiled.</LINE>
<LINE>As waggish boys in game themselves forswear,</LINE>
<LINE>So the boy Love is perjured every where:</LINE>
<LINE>For ere Demetrius look'd on Hermia's eyne,</LINE>
<LINE>He hail'd down oaths that he was only mine;</LINE>
<LINE>And when this hail some heat from Hermia felt,</LINE>
<LINE>So he dissolved, and showers of oaths did melt.</LINE>
<LINE>I will go tell him of fair Hermia's flight:</LINE>
<LINE>Then to the wood will he to-morrow night</LINE>
<LINE>Pursue her; and for this intelligence</LINE>
<LINE>If I have thanks, it is a dear expense:</LINE>
<LINE>But herein mean I to enrich my pain,</LINE>
<LINE>To have his sight thither and back again.</LINE>
</SPEECH>

<SCENE><TITLE>SCENE II. Athens. QUINCE'S house.</TITLE>
<STAGEDIR>Enter QUINCE, SNUG, BOTTOM, FLUTE, SNOUT, and
STARVELING</STAGEDIR>

<SPEECH>
<SPEAKER>BOTTOM</SPEAKER>
<LINE>You were best to call them generally, man by man,</LINE>
<LINE>according to the scrip.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>QUINCE</SPEAKER>
<LINE>Here is the scroll of every man's name, which is</LINE>
<LINE>thought fit, through all Athens, to play in our</LINE>
<LINE>interlude before the duke and the duchess, on his</LINE>
<LINE>wedding-day at night.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>BOTTOM</SPEAKER>
<LINE>First, good Peter Quince, say what the play treats</LINE>
<LINE>on, then read the names of the actors, and so grow</LINE>
<LINE>to a point.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>QUINCE</SPEAKER>
<LINE>Marry, our play is, The most lamentable comedy, and</LINE>
<LINE>most cruel death of Pyramus and Thisby.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>BOTTOM</SPEAKER>
<LINE>A very good piece of work, I assure you, and a</LINE>
<LINE>merry. Now, good Peter Quince, call forth your</LINE>
<LINE>actors by the scroll. Masters, spread yourselves.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>QUINCE</SPEAKER>
<LINE>Answer as I call you. Nick Bottom, the weaver.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>BOTTOM</SPEAKER>
<LINE>Ready. Name what part I am for, and proceed.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>QUINCE</SPEAKER>
<LINE>A lover, that kills himself most gallant for love.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>BOTTOM</SPEAKER>
<LINE>That will ask some tears in the true performing of</LINE>
<LINE>it: if I do it, let the audience look to their</LINE>
<LINE>eyes; I will move storms, I will condole in some</LINE>
<LINE>measure. To the rest: yet my chief humour is for a</LINE>
<LINE>tyrant: I could play Ercles rarely, or a part to</LINE>
<LINE>tear a cat in, to make all split.</LINE>
<LINE>The raging rocks</LINE>
<LINE>And shivering shocks</LINE>
<LINE>Shall break the locks</LINE>
<LINE>Of prison gates;</LINE>
<LINE>And Phibbus' car</LINE>
<LINE>Shall shine from far</LINE>
<LINE>And make and mar</LINE>
<LINE>The foolish Fates.</LINE>
<LINE>This was lofty! Now name the rest of the players.</LINE>
<LINE>This is Ercles' vein, a tyrant's vein; a lover is</LINE>
<LINE>more condoling.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>FLUTE</SPEAKER>
<LINE>Nay, faith, let me not play a woman; I have a beard coming.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>QUINCE</SPEAKER>
<LINE>That's all one: you shall play it in a mask, and</LINE>
<LINE>you may speak as small as you will.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>BOTTOM</SPEAKER>
<LINE>An I may hide my face, let me play Thisby too, I'll</LINE>
<LINE>speak in a monstrous little voice. 'Thisne,</LINE>
<LINE>Thisne;' 'Ah, Pyramus, lover dear! thy Thisby dear,</LINE>
<LINE>and lady dear!'</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>QUINCE</SPEAKER>
<LINE>No, no; you must play Pyramus: and, Flute, you Thisby.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>QUINCE</SPEAKER>
<LINE>Robin Starveling, you must play Thisby's mother.</LINE>
<LINE>Tom Snout, the tinker.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>QUINCE</SPEAKER>
<LINE>You, Pyramus' father: myself, Thisby's father:</LINE>
<LINE>Snug, the joiner; you, the lion's part: and, I</LINE>
<LINE>hope, here is a play fitted.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>SNUG</SPEAKER>
<LINE>Have you the lion's part written? pray you, if it</LINE>
<LINE>be, give it me, for I am slow of study.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>QUINCE</SPEAKER>
<LINE>You may do it extempore, for it is nothing but roaring.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>BOTTOM</SPEAKER>
<LINE>Let me play the lion too: I will roar, that I will</LINE>
<LINE>do any man's heart good to hear me; I will roar,</LINE>
<LINE>that I will make the duke say 'Let him roar again,</LINE>
<LINE>let him roar again.'</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>QUINCE</SPEAKER>
<LINE>An you should do it too terribly, you would fright</LINE>
<LINE>the duchess and the ladies, that they would shriek;</LINE>
<LINE>and that were enough to hang us all.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>BOTTOM</SPEAKER>
<LINE>I grant you, friends, if that you should fright the</LINE>
<LINE>ladies out of their wits, they would have no more</LINE>
<LINE>discretion but to hang us: but I will aggravate my</LINE>
<LINE>voice so that I will roar you as gently as any</LINE>
<LINE>sucking dove; I will roar you an 'twere any</LINE>
<LINE>nightingale.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>QUINCE</SPEAKER>
<LINE>You can play no part but Pyramus; for Pyramus is a</LINE>
<LINE>sweet-faced man; a proper man, as one shall see in a</LINE>
<LINE>summer's day; a most lovely gentleman-like man:</LINE>
<LINE>therefore you must needs play Pyramus.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>BOTTOM</SPEAKER>
<LINE>Well, I will undertake it. What beard were I best</LINE>
<LINE>to play it in?</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>BOTTOM</SPEAKER>
<LINE>I will discharge it in either your straw-colour</LINE>
<LINE>beard, your orange-tawny beard, your purple-in-grain</LINE>
<LINE>beard, or your French-crown-colour beard, your</LINE>
<LINE>perfect yellow.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>QUINCE</SPEAKER>
<LINE>Some of your French crowns have no hair at all, and</LINE>
<LINE>then you will play bare-faced. But, masters, here</LINE>
<LINE>are your parts: and I am to entreat you, request</LINE>
<LINE>you and desire you, to con them by to-morrow night;</LINE>
<LINE>and meet me in the palace wood, a mile without the</LINE>
<LINE>town, by moonlight; there will we rehearse, for if</LINE>
<LINE>we meet in the city, we shall be dogged with</LINE>
<LINE>company, and our devices known. In the meantime I</LINE>
<LINE>will draw a bill of properties, such as our play</LINE>
<LINE>wants. I pray you, fail me not.</LINE>
</SPEECH>

<SPEECH>
<SPEAKER>BOTTOM</SPEAKER>
<LINE>We will meet; and there we may rehearse most</LINE>
<LINE>obscenely and courageously. Take pains; be perfect: adieu.</LINE>
</SPEECH>

надо посчитать количесво элементов LINE соответствующий каждому SPEAKERу И PERSONA
я делаю так:

Код
<xsl:for-each select="//PERSONA">
<xsl:variable name="person">
<xsl:value-of select="."/>
</xsl:variable>

но код выдает общее количество строк во всем акте, как выводить соответствующее кол-во LINE соответствующее каждому SPEAKER и PERSONA

Профиль
Группа: Участник
Сообщений: 920
Регистрация: 6.1.2008

Репутация: 5
Всего: 31

Не очень понял что вы хотите, но я думаю вам поможет функция count
count считает количество узлов в выборке XPath

Код
<A>
<B>
<B>
</B>
</B>
<A>
<B/>
</A>
</A>

например это выведет "3" — общее количество элементов B

Код
<xsl:value-of select="count(//B)"/>

например это выведет "1" — количество элементов B который лежат в двух А

Код
<xsl:value-of select="count(/A/A/B)"/>

Профиль
Группа: Участник
Сообщений: 3
Регистрация: 12.5.2009

Репутация: нет
Всего: нет

Код
<xsl:choose>
<xsl:when test="contains(substring-after($speaker1, ' '),substring-before($person,','))">
<xsl:value-of select="count(child::LINE)"/>
</xsl:when>
<xsl:when test="$speaker1=substring-before($person,',')">
<xsl:value-of select="count(child::LINE)"/>

сначала я проверяю совпажает ли SPEAKER и PERSONA , а потом спускаюсь чтоб посчитать LINE
но count() не суммирует, а выводит 1

Это сообщение отредактировал(а) Mizhasoul — 12.5.2009, 10:22

Профиль
Группа: Участник
Сообщений: 3
Регистрация: 12.5.2009

Репутация: нет
Всего: нет

Профиль
Группа: Участник
Сообщений: 920
Регистрация: 6.1.2008

Репутация: 5
Всего: 31

Прежде чем опубликовать вопрос, попробуйте воспользоваться поиском — возможно тема уже поднималась.

Также рекомендуем Вам зайти в раздел FAQ ,раздел дополняется и, возможно, там вы увидите готовое решение.

Для ответов на часто задаваемые вопросы существует FAQ раздела. Новости можно публиковать в разделе новостей. Для статей так же есть специальный раздел

Желаем удачи в Вашем деле!

Если Вам понравилась атмосфера форума, заходите к нам чаще! С уважением, diadiavova.

0 Пользователей читают эту тему (0 Гостей и 0 Скрытых Пользователей)
0 Пользователей:
« Предыдущая тема | XML, XSL | Следующая тема »

[ Время генерации скрипта: 0.1259 ] [ Использовано запросов: 20 ] [ GZIP включён ]

Как посчитать количество элементов в XML Doc

Я здесь новый, и я думаю, вы, ребята, самые лучшие, так что здесь.

Вот моя проблема. Я осмелился создать целый блог-сайт, основанный исключительно на XML — без баз данных. Пока что я делаю очень хорошо. У меня только одна проблема, которая удерживает меня от завершения этого проекта.

У меня есть XML-документ «Комментарии к блогам»:

Я хотел бы иметь возможность подсчитать количество комментариев, прикрепленных к первому узлу blogId (?).

До сих пор я открыл документ и умею читать, но я не знаю, как считать. Мысли?

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *