Skip to content

Commit

Permalink
Fix output of political orientation.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomazErjavec committed Aug 20, 2023
1 parent de451fb commit 694fb13
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Scripts/parlamint-lib.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,39 @@
</xsl:choose>
</xsl:function>

<!-- Output left-right orientation of the speaker's party when speaking -->
<xsl:function name="et:party-orientation" as="xs:string">
<xsl:param name="speaker" as="element(tei:person)"/>
<!-- Collect all affiliation references where the speaker is a member and are in
the correct time-frame for the speech -->
<xsl:variable name="refs" select="et:speaker-affiliations-refs($speaker)"/>
<xsl:variable name="parliamentaryGroups">
<xsl:for-each select="distinct-values(tokenize($refs, ' '))">
<xsl:variable name="party" select="key('idr', ., $rootHeader)[@role='parliamentaryGroup']"/>
<xsl:call-template name="party-orientation">
<xsl:with-param name="party" select="$party"/>
</xsl:call-template>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="politicalParties">
<xsl:for-each select="distinct-values(tokenize($refs, ' '))">
<xsl:variable name="party" select="key('idr', ., $rootHeader)[@role='politicalParty']"/>
<xsl:call-template name="party-orientation">
<xsl:with-param name="party" select="$party"/>
</xsl:call-template>
</xsl:for-each>
</xsl:variable>
<xsl:choose>
<xsl:when test="normalize-space($parliamentaryGroups)">
<xsl:value-of select="replace($parliamentaryGroups, ';$', '')"/>
</xsl:when>
<xsl:when test="normalize-space($politicalParties)">
<xsl:value-of select="replace($politicalParties, ';$', '')"/>
</xsl:when>
<xsl:otherwise><xsl:text></xsl:text></xsl:otherwise>
</xsl:choose>
</xsl:function>

<!-- Output the name of the party (or parties!) the speaker belongs to when speaking -->
<xsl:function name="et:speaker-party" as="xs:string">
<xsl:param name="speaker" as="element(tei:person)"/>
Expand Down Expand Up @@ -559,6 +592,25 @@
</xsl:choose>
</xsl:template>

<!-- Return the political orientation of the party, either from Wikipedia, or, if missing, encoder -->
<xsl:template name="party-orientation">
<xsl:param name="party"/>
<xsl:variable name="orientation" select="$party/tei:state[@type = 'politicalOrientation']"/>
<xsl:choose>
<xsl:when test="$orientation/tei:state[@type = 'Wikipedia']">
<xsl:value-of select="key('idr', $orientation/tei:state[@type = 'Wikipedia']/@ana, $rootHeader)//
tei:term[ancestor-or-self::tei:*[@xml:lang][1]/@xml:lang = 'en']"/>
</xsl:when>
<xsl:when test="$orientation/tei:state[@type = 'encoder']">
<xsl:value-of select="key('idr', $orientation/tei:state[@type = 'encoder']/@ana, $rootHeader)//
tei:term[ancestor-or-self::tei:*[@xml:lang][1]/@xml:lang = 'en']"/>
</xsl:when>
<xsl:otherwise>
<xsl:text></xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- Notes and incidents normalization - removing brackets and normalize spces-->
<xsl:function name="mk:normalize-note" as="xs:string">
<xsl:param name="noteIn" as="xs:string"/>
Expand Down
1 change: 1 addition & 0 deletions Scripts/parlamint2xmlvert.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<xsl:attribute name="speaker_party" select="et:speaker-party($speaker, 'abb')"/>
<xsl:attribute name="speaker_party_name" select="et:speaker-party($speaker, 'yes')"/>
<xsl:attribute name="party_status" select="et:party-status($speaker)"/>
<xsl:attribute name="party_orientation" select="et:party-orientation($speaker)"/>
<xsl:attribute name="speaker_gender" select="$speaker/tei:sex/@value"/>
<xsl:attribute name="speaker_birth" select="replace($speaker/tei:birth/@when, '-.+', '')"/>
</xsl:when>
Expand Down

0 comments on commit 694fb13

Please sign in to comment.